• 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

Collections and Garbage Collection

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have a collection item, such as an ArrayList, and I null out the ArrayList reference, will that be garbage collected? What about all the items in the ArrayList? Do I need to go through and null out everything in the ArrayList first before nulling the ArrayList reference? My app has nested collection elements (a HashMap that contains a HashMap that contains ArrayList) and I want to be able to make sure that I am not leaving anything so that the garbage collector will not collect everything when I am done. So do I need to null out everything manually so I don't get a memory leak?
Thanks for the help
Brian
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that you aren't maintaining a reference to the ArrayList somewhere else in your program, if you do null it out, then it will be eligible for garbage collection, and will be garbage collected eventually.
At that point, if you also don't have references to the items in the ArrayList, they will be eligible for garbage collection also.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic