Finalizers Are Not Destructors

C++ programmers tend to think that the finalize() method is equivalent to a destructor. This is not true, for two reasons:There is no guarantee that a finalizer will ever be called. Finalizers do not automatically propagate up the inheritance chain like destructors.It is clearly defined when a destructor will be executed- however it is undefined when a finalizer will be called. In particular, you should manually call super.finalize() from all your finalize methods. There is no guarantee about the order of invocation of finalizers. There are two System methods you should be aware of:

System.runFinalization() 
System.runFinalizersOnExit(boolean value)


System.runFinalization Runs the finalization methods of any objects pending finalization. System.runFinalizersOnExit is deprecated. It causes all finalizer methods to be invoked before exiting.

This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock.

FAQ Home

 
Printer friendly version of the FAQ-JAVA-Finalizers-Are-Not-Destructors page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
Virtual File System SDK
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.