aspose file tools
The moose likes Java in General and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
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
    
    3

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection
 
Similar Threads
gc
garbage collector
Garbage Collection Question
one question about gc?
KHALIDS book-CONTRADICTION on GC