ReferenceQueueRetainedObjectTracker

ReferenceQueueRetainedObjectTracker can be passed objects to expectDeletionOnTriggerFor. It will create KeyedWeakReference instances that reference tracked objects, and check if those references have been cleared as expected. If not, these objects are considered retained and ReferenceQueueRetainedObjectTracker will then notify registered OnObjectRetainedListeners. ReferenceQueueRetainedObjectTracker is thread safe.

Constructors

Link copied to clipboard
constructor(clock: UptimeClock, onObjectRetainedListener: OnObjectRetainedListener)

Functions

Link copied to clipboard
open override fun clearAllObjectsTracked()
Link copied to clipboard
open override fun clearObjectsTrackedBefore(uptime: Duration)

Clears weak reachability expectations for objects that were created before uptime.

Link copied to clipboard

Start tracking the provided target object, with the expectation that it should be eligible for automatic garbage collection soon, i.e. that it should not be strongly reachable by the time RetainTrigger.markRetainedIfStronglyReachable is called on the returned RetainTrigger.

Properties

Link copied to clipboard
open override val hasRetainedObjects: Boolean

Returns true if any of the tracked objects are currently retained.

Link copied to clipboard
open override val hasTrackedObjects: Boolean

Returns true if there are any tracked objects that aren't currently weakly reachable.

Link copied to clipboard
open override val retainedObjectCount: Int

Returns the number of retained objects.

Link copied to clipboard

Subset of trackedWeakReferences that have been marked as retained.

Link copied to clipboard
open override val trackedObjectCount: Int

Returns the number of tracked objects that aren't weakly reachable.

Link copied to clipboard

List of KeyedWeakReference that have not been enqueued in the reference queue yet, which means their referent is most likely still strongly reachable.