Java finalization, present since day one, was designed to prevent resource leaks by tying resource release to garbage collection. However, it has serious flaws: resources are released at an arbitrary future time, finalization order and threads are unspecified, subclasses can interfere, objects can be resurrected (a security risk), and there is a measurable performance overhead. JEP 421 proposes deprecating finalization for removal in Java 18/19, adding a command-line flag to disable it entirely for testing. The recommended replacements are try-with-resources with AutoCloseable, Project Panama's foreign memory API for off-heap memory, and the Cleaner API as a last resort. The broader context is Java's decade-long effort to phase out outdated mechanisms like the applet API and security manager. JEP 416 is also briefly covered, which reimplements core reflection using method handles to reduce maintenance burden.
Sort: