How does Java Garbage collector handle self-reference?

后端 未结 7 695
庸人自扰
庸人自扰 2020-11-27 19:23

Hopefully a simple question. Take for instance a Circularly-linked list:

class ListContainer
{
  private listContainer next;
  <..>

  public void setN         


        
7条回答
  •  离开以前
    2020-11-27 20:06

    Circular references is a (solvable) problem if you rely on counting the references in order to decide whether an object is dead. No java implementation uses reference counting, AFAIK. Newer Sun JREs uses a mix of several types of GC, all mark-and-sweep or copying I think.

    You can read more about garbage collection in general at Wikipedia, and some articles about java GC here and here, for example.

提交回复
热议问题