posted 9 years ago
Any search to google will tell you that its called implicitly by the GC when it determines that the object cannot be reached. I believe putting anything much in it is discouraged, even to the point of never using it.
<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
posted 9 years ago
As Tom said, it is called automatically by the GC. But you can still call it explicitly but that is discouraged and that will not destroy the object from the heap. Also the finalize method has been declared protected in the Object class so that you can make it inaccessible from outside your class and its sub classes. This is done solely to restrict any code outside your class (and its sub classes) from calling the finalize method...
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
posted 9 years ago
You might want to read this : Effective Java: Item 6 Avoid Finalizers
[List of FAQs] | [Android FAQ] | [Samuh Varta]
Sandeep Kumar Jakkaraju
Ranch Hand
Posts: 75
posted 9 years ago
If you do, always call super.finalize():
I usually only add finalizers to make sure that resources are released, but I always provide means to release resources explicitly. Like Monu's link says, finalizers should only be used as a safety net of sorts; never rely on it, only use it "just in case".
Sandeep Kumar Jakkaraju wrote:I guess we can override the defualt finalize() method !!! .......... may be sometimes useful..to make the members null referenced !!
If you do, always call super.finalize():
I usually only add finalizers to make sure that resources are released, but I always provide means to release resources explicitly. Like Monu's link says, finalizers should only be used as a safety net of sorts; never rely on it, only use it "just in case".
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions

Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
|