Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Garbage Collection

 
Greenhorn
Posts: 2
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic