Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how does java garbage collector handle self reference using -'java,garbage-collection'


how does java garbage collector handle self reference  using -'java,garbage-collection'

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

class ListContainer
{
  private listContainer next;
  <..>

  public void setNext(listContainer next)
  {
    this.next = next;
  }
}

class List
{
  private listContainer entry;
  <..>
}


Now since it's a circularly-linked list, when a single elemnt is added, it has a reference to itself in it's next variable. When deleting the only element in the list, entry is set to null. Is there a need to set ListContainer.next to null as well for Garbage Collector to free it's memory or does it handle such self-references automagically?
    

asked Sep 7, 2015 by rajesh
0 votes
8 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...