This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
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
Joined: Sep 23, 2000
Posts: 149
posted
0
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
Joined: Oct 23, 2000
Posts: 77
posted
0
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
Joined: Mar 17, 2000
Posts: 5782
posted
0
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
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Milind Mahajan
Ranch Hand
Joined: Oct 23, 2000
Posts: 77
posted
0
Hi, Thank you very much for the answer Ajith. Milind.