Can you even be 100% sure that the finalize method will ever run?
I thought I read somewhere that if the app exits and the JVM shuts down it doesn't have to bother with all the objects that can be collected since the whole
java heap is about to be thrown away. That means that even if the garbage collector had marked some objects as collectable so they are on a list of object for which the finalize method should be invoked, there still may be some objects that the collector hasn't found yet and as i understand it there is no requirement that it clean up everything neatly if the JVM is being shut down.
Normally if the JVM shuts down the process is ending and the resources it had a hold on are released to the undrelying OS anyway.. but if you are trying to use finalize methods in other ways e.g. like decrementing a reference count to some bit of native code stuff that may still be running when the VM exits you could be in trouble..
Could someone with more experience confirm this or set me straight?