AI-generated Key Takeaways
-
CleanupRegistry
manages resource cleanup by tracking objects and executing cleanup logic when they are garbage collected. -
It utilizes a
ReferenceQueue
to monitor garbage collection and aRunnable
to perform cleanup tasks. -
CleanupRegistry
allows registering objects for tracking and provides methods for manual resource release and reclaiming released resources. -
The
register
method 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 |
destroyAllResources()
Ignores reference count and releases any associated resources
|
long |
reclaimReleasedResources()
Polls the
ReferenceQueue for garbage collected objects and runs the associated Runnable |
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.
|