harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Giampaolo Tomassoni" <Giampa...@Tomassoni.biz>
Subject GC wonders
Date Mon, 23 Aug 2010 10:41:13 GMT
I have a question to spare, which arouses me by ages: how does the JVM
elegits circularly-referenced objects for garbage collection?

Let me explain it better. Having 2 classes:

public class A {
	B b;

public class B {
	A a;

and instantiating them in such a way to have the A instance refer to the B
one via its b field, and the B instance refer the A one via its a field,
when there isn't anymore other references to the instance of A and the
instance of B apart their own circular references, how can the JVM GC
understand that they may be both garbage-collected.

Or instead they are simply not recollected and the various WeakReference
versions are there exactly to avoid non-recollectable circular references?



View raw message