API reference

MainThreadCleanup Object

Utility for safely cleaning up objects that require main thread destruction.
This solves the problem where finalize() posts a destroy call to the main thread, but the object may be GC'd before the destroy runs. This utility holds a strong reference to the object until the cleanup completes on the main thread.

Signature

object MainThreadCleanup

Methods

scheduleCleanup ( obj , cleanup )
Schedule cleanup on the main thread while keeping the object alive.
Signature
fun <T : Any> scheduleCleanup(obj: T, cleanup: (T) -> Unit)
Parameters
obj: MainThreadCleanup  The object to keep alive during cleanup
cleanup: Function1  The cleanup function to run on the main thread