Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: the great puzzle of finalizing
|
Posted: May 13, 2002 10:55 PM
|
|
I think the main point about finalizers is that they are practically useless. I think Bruce even suggested that the only marginal use that might squeezed out of them is a kind of debug-check thing where they only verify that an object that should have released resources (via a close() method, or something similar) has done so before the finalizer is hit; however, even this has the caveate that there is no guarantee that the finalizer will be called. This is true even if you use System.gc(). System.gc() does not force finalizers to be called -- rather it suggests to the JVM that now would be a good time to do it, if the JVM is so inclined[/b]. In other words, for spot-checking purposes if the finalizer is called and the resource hasn't been released, then you can raise a flag, which may help in improving the quality of the code. However, since there is no guarantee that the finalizer will ever be called, you definitely do not want to use it for resource freeing or anything else important.
What this really all boils down to is the simple fact that finalizers are not important.
|
|