4 ms·
Which is why finalizers in Java have been officially deprecated [1] and might be removed altogether in a future release. [1]: https://docs.oracle.com/en/java/j
by pron 6y ago
Which is why finalizers in Java have been officially deprecated [1] and might be removed altogether in a future release.
[1]: https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/Object.html#finalize() https://docs.oracle.com/en/java/javase/14/docs/api/java.base...
- cesarb 6y agoUnfortunately, the alternative they recommend (Cleaner) only exists since Java 9, so it cannot be used by libraries that wish to remain compatible with Java 8 (which, in my experience, is most or all of them; so far, I haven't seen any Java library which has dropped compatibility with Java 8, and many only recently dropped compatibility with Java 6 or 7).
- altfredd 6y agoThe actual alternative is PhantomReference, which exists since ancient times. Cleaner simply provides safe way to use PhantomReferences, which are rather tricky to use (by Java standards).