-
Notifications
You must be signed in to change notification settings - Fork 187
Closed
Description
Is your feature request related to a problem? Please describe.
The current implementation to make Resource.setNonDisposehandler(Consumer) work, uses finalize() under the hood:
Lines 74 to 81 in 4d68329
| protected void finalize() { | |
| if (ignoreMe) return; | |
| if (nonDisposedReporter == null) return; | |
| // If the Resource is GC'ed before it was disposed, this is a leak. | |
| if (!resource.isDisposed()) | |
| nonDisposedReporter.accept(allocationStack); | |
| } |
This method is deprecated for removal since Java 18 as described in JEP 421.
Describe the solution you'd like
We should rewrite this functionality using PhantomReferences and a daemon thread polling from the shared ReferenceQueue.
Describe alternatives you've considered
The cleaner API might also work:
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/ref/Cleaner.html
Metadata
Metadata
Assignees
Labels
No labels