There are other factors that might affect when the objects are
collected, like size and age of the objects. But, yes, the GC will
recognise both of the objects as up for collection at the same run
(unless they are in different generations, and the garbage collection
run only considers the first generation).
When the garbage collector runs it starts out by considering all objects
as collecteable, then looks through all references to exclude objects
that aren't collectable. It doesn't look for references in objects that
are collectable, so as A is collectable, the reference to B doesn't keep
B from being collectable.
Ron M. Newman wrote:
> Hi,
>
> Let's say I have an object A.
>
> Object A exclusively references object B.
>
> Now: Object A goes out of scope.
>
> does this mean the system garbage collects object A and B together?
>
> I think it should. Am I correct?
>
> Thanks
> -Ron
>
>
|