...
- There is no fixed time at which finalizers must be executed ; as this detail depends on the JVM. The only guarantee is that any finalizer method that executes will do so sometime after the associated object has become unreachable (detected during the first cycle of garbage collection), and sometime before the garbage collector reclaims the associated object's storage (during the garbage collector's second cycle). Execution of an object's finalizer may be delayed for an arbitrarily long time after the object becomes unreachable. Consequently, avoid implementing time-critical functionality in an object's
finalize()
method. For instance, closing file handles in a finalizer is not recommended.
...
- Coding errors that result in memory leaks imply that objects incorrectly remain reachable; thus consequently their finalizers are never invoked.
...