18bytes
18bytes

Reputation: 6029

Large circular reference and JVM garbage collector

Is JVM capable of finding large circular reference and collect the objects? Is there any official documentation/link which states the same? or do you have any good/bad experiences with Garbage collection of large circular references.

Update link: http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997442

Upvotes: 3

Views: 463

Answers (2)

RHSeeger
RHSeeger

Reputation: 16262

From a simplistic view, the JVM uses a Tracing Garbage Collection, Mark-and-Sweep. Circular references don't interfere with the correct behavior of such an algorithm because it starts from the "base" level and works it's way through references to find those elements that can be reached from there. Any that cannot be reached are available to be collected/freed.

It's worth noting that the JVM garbage collectors are generally a lot more complex than this, with many optimizations to make things faster. That being said, the general properties of the mark-and-sweep algorithm hold true for it.

Upvotes: 12

Jack Edmonds
Jack Edmonds

Reputation: 33171

Yes. The JVM's garbage collector can deal with circular references.

The garbage collector employed by the JVM is not a reference-counting garbage collector. Instead, it finds garbage by tracing from references that are still accessable (references on all Threads' stacks or static references).

Upvotes: 3

Related Questions