Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the use of finalize() #331

Open
minborg opened this issue Jan 10, 2022 · 0 comments
Open

Remove the use of finalize() #331

minborg opened this issue Jan 10, 2022 · 0 comments
Assignees

Comments

@minborg
Copy link
Contributor

minborg commented Jan 10, 2022

Overriding finalize() introduces a number of drawbacks including (but not limited to) escape analysis of such objects will always fail, dead-locks, resurrections, memory leaks, and that the finalize task is run as a part of the GC process potentially prolonging GCs which is especially unpleasant during stop-the-world collections. Also, finalize() is deprecated in Java 9 and onwards.

It would be much better to introduce a Reference-based cleanup of objects that are unreachable.

Elaborations on drawbacks:
https://medium.com/javarevisited/time-to-say-goodbye-to-the-finalize-method-in-java-a2f5b7e4f1b1

Implementation examples:
http://blog.ragozin.info/2016/03/finalizers-and-references-in-java.html
https://unitstep.net/blog/2018/03/10/java-phantomreferences-a-better-choice-than-finalize/

@minborg minborg self-assigned this Jan 10, 2022
@RobAustin RobAustin assigned peter-lawrey and unassigned minborg May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants