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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays and GC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Arrays and GC" Watch "Arrays and GC" New topic
Author

Arrays and GC

Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
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
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
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
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
Hi,
Thank you very much for the answer Ajith.
Milind.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Arrays and GC
 
Similar Threads
How to discard objects stored in an ArrayList
GC doubt!
Questions on GC from Khalid A.Mughal, Chap 9
garbage collection
Arrays& GCs