Never rely on finalize

You cannot rely on finalize to always reclaim resources. Instead, if an object has resources which need to be recovered, it must define a method for this very purpose - for example a cleanupResources method, or a dispose method. The caller is then required to use such a method in order to ensure that the related resources are recovered.

For an extensive discussion, please see the "Avoid Finalizers" topic in Effective Java.

System.runFinalizersOnExit(boolean) is deprecated.

See Also :
Recovering resources
Would you use this technique?
Yes   No   Undecided   
© 2013 Hirondelle Systems | Source Code | Contact | License | RSS
Individual code snippets can be used under this BSD license - Last updated on August 30, 2012.
Over 2,400,000 unique IPs last year - Built with WEB4J.
- In Memoriam : Bill Dirani -