-
Enhancement
-
Resolution: Fixed
-
P3
-
9
-
b99
It is not a goal to replace all uses of finalization or sun.misc.Cleaner. Investigation will evaluate if and in what cases the cleaner can replace finalization.
Finalization has a long history of issues both in usage and performance. PhantomReferences have been proposed as the alternative GC based mechanism for cleaning functions but it has been left as an exercise to the developer to construct the necessary mechanisms to handle ReferenceQueues, handle threading issues and robust termination.
The Cleaner performs cleaning functions when objects are unreachable as found by garbage collection using the existing mechanisms of PhantomReference, WeakReference, SoftReferences, and ReferenceQueues. It manages a thread that dequeues references to unreachable objects and invokes the corresponding cleaning function. Registered cleaning functions can be cleared if no longer needed, can be invoked explicitly to perform the cleanup immediately, or be invoked when the object is not reachable (as detected by garbage collection) and handled by a cleanup thread.
The java.lang.ref package is proposed for the Cleaner because it is complementary to the reference classes and reference queues and to make it easy to find.
- duplicates
-
JDK-4701292 non-resurrectible finalization mechanism required
-
- Closed
-
-
JDK-6534574 (ref) I offer a tool for finalization via PhantomReference
-
- Closed
-
- relates to
-
JDK-8291867 Cleaner has reachabilityFence in wrong place
-
- Open
-
-
JDK-8145459 Cleaner - use Reference.reachabilityFence
-
- Closed
-
-
JDK-8145434 Cleaner - improve example with concrete details
-
- Closed
-
-
JDK-8051843 Public API alternative for sun.misc.Cleaner
-
- Closed
-
-
JDK-8145041 A common Cleaner for general use may be useful
-
- Closed
-
-
JDK-8146028 Common Cleaner for finalization replacements in OpenJDK
-
- Resolved
-
-
JDK-8146038 CleanerImpl should not depend on ManagedLocalsThread
-
- Resolved
-
-
JDK-8144531 Cleanup of Cleaner implementation
-
- Closed
-