File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays and GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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://aspose.com/file-tools
 
subject: Arrays and GC