• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic