If I have a linked list structure, and I implement the clear () method as follows:
public void clear() {
firstNode = null;
size = 0;
}
will it still correctly collect garbage, or do I want to go through each node by setting the next Node to null?
None of the nodes can be directly linked to a link outside the linked list, so there is no case when there will be a link to any of them outside my class, but I'm not sure that Java correctly collects the remaining chains of nodes.
source
share