| Author |
Garbage Collection
|
Animesh Aries
Greenhorn
Joined: Apr 16, 2012
Posts: 2
|
|
Hi,
If I have a List of a user defined type say L1, lets say class "Developers" object.
I have ten objects of class "Developers", D1, D2, D3, D4, D5, D6, D7, D8, D9 and D10.
I create another List L2 of "Developers" objects and assign the existing references of D2, D5, D7 and D9 into this List.
Now, I do this -- L2 = null;
Is the object of List L2 now eligible for garbage collection ? But, it is still having object variables holding live references to D2, D5, D7 and D9, is L2 eligible for garbage collection ?
If Yes, why ? And If No, why ?
All your answers are welcome.
Thanks
Animesh
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
|
If nothing else has a reference to list L2, then yes, L2 is eligible for garbage collection. It doesn't matter that L2 itself has references to objects that are still "live".
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Mittal Vishal
Greenhorn
Joined: Nov 13, 2006
Posts: 21
|
|
Hi,
If L2 does not have any active references then it is eligible for garbage collection irrespective of whether it has references to objects which are still active.
Thanks
Vishal
|
 |
 |
|
|
subject: Garbage Collection
|
|
|