This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays and GC

 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question on arrays and GC. Suppose there is an array of objects. If I set objects contained in the array to null, will they become eligible for GC ? Or they won't become eligible for GC until the array object itself is set to null ?
Is there any way to find programmatically which references are eligible for GC ?
Thanks,
Milind.
 
Prasad Ballari
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Milind,
Arrays are nothing but pointers they hold the reference of the objects . You can set reference to null,that will not affect the entire array.
The object is sent to GC after all the refrences for that object is removed.So when an object reference is removed from the array then that object is elegible for GC provided it does not have any other references.

Prasad


 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Prasad, Thanks a lot for the response. I think I understood it now.
But can somebody tell me whether we can programmatically find which references are eligible for GC ?
Thanks
Milind.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there is no way to "inspect" an object to see if it is eligible for GC( and going to get garbage collected soon ). On the brighter side, you can however, override the <code>finalize</code> method which the VM calls when the object is about to get garbage-collected. This means, any code in the overridden <code>finalize</code> method gets called ONLY WHEN the object is going to get collected.
Ajith
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you very much for the answer Ajith.
Milind.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic