wood burning stoves
The moose likes Beginning Java and the fly likes garbage collector question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "garbage collector question" Watch "garbage collector question" New topic

garbage collector question

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Which of the following statements are true?

1) finalize will always run before an object is garbage collected
2) finalize may run before or after an object is garbage collected
3) finalize will run when an object becomes unreachable
4) finalize allows a programmer to free memory allocated to an object

I was trying above question from link

Finalize will always be run before an object is garbage collected. It cannot run after it is collected because by then the object will cease to exit. When an object becomes unreachable it will be eligible for garbage collection but there is no guarantee when finalize will run, only that it will run before garbage collection happens. The final option is a passable description of destructors in C++ but not of the finalize method in Java.

I have not understood clearly explanation in terms of relation between garbage collection and finalize method. Any ideas, resources, links, sample code highly appreciated. thanks in advance.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46383
Effective Java by Joshua Bloch; there are details here.
I agree. Here's the link: http://aspose.com/file-tools
subject: garbage collector question
It's not a secret anymore!