Skip to content

Remove the use of finalize() #331

Open
@minborg

Description

@minborg

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/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions