Page Summary
-
CleanupRegistrymanages resource cleanup by tracking objects and executing cleanup logic when they are garbage collected. -
It utilizes a
ReferenceQueueto monitor garbage collection and aRunnableto perform cleanup tasks. -
CleanupRegistryallows registering objects for tracking and provides methods for manual resource release and reclaiming released resources. -
The
registermethod associates a cleanup callback (Runnable) with an object, ensuring the callback is executed upon garbage collection.
Maintains a ReferenceQueue
and executes a Runnable
after each object in the queue
is garbage collected.
Public Constructors
| * | |
| * |
Public Methods
| void | |
| long | |
| void |
Inherited Methods
Public Constructors
public CleanupRegistry ()
public CleanupRegistry ( HashSet <CleanupItem<T>> cleanupItemHashSet, ReferenceQueue <T> referenceQueue)
Parameters
| cleanupItemHashSet |
|---|
| referenceQueue |
Public Methods
public void destroyAllResources ()
Ignores reference count and releases any associated resources
public long reclaimReleasedResources ()
Polls the ReferenceQueue
for garbage collected objects and runs the associated Runnable
Returns
- count of resources remaining.
public void register (T trackedObject, Runnable cleanupCallback)
Adds trackedOBject
to the ReferenceQueue
.
Parameters
| trackedObject | The target to be tracked. |
|---|---|
| cleanupCallback | Will be called after trackedOBject
is disposed. |

