MainThreadFinalizerProcessor

This objects allows to customize the behavior of the finalizer processor that runs on the main thread.

On Apple platforms Kotlin/Native releases ObjC/Swift objects that were passed to Kotlin when it processes the finalizers after GC. Kotlin/Native can also utilize main run loop to release objects that were passed to Kotlin on the main thread. This can be turned off by setting objcDisposeOnMain binary option to false. For more information, see iOS integration.

This finalizer processor works as follows:

  • Finalizers that must be run on the main thread get scheduled by the GC after the main GC phase is finished

  • A task will be posted on the main run loop in which the scheduled finalizers will start processing

  • Finalizers will be processed inside an autoreleasepool in batches of size batchSize

  • If at some point during task the processor detected that more than maxTimeInTask has passed, it will stop and post another task to the main thread to continue processing finalizers later. Note that if some finalizer takes a very long time, the task will still process the entire batchSize and may significantly overflow maxTimeInTask

  • It's guaranteed that the time interval between tasks is at least minTimeBetweenTasks.

maxTimeInTask and minTimeBetweenTasks allow other tasks posted on the main thread (e.g. UI events) be processed without significant delays.

Since Kotlin

1.9

Properties

Link copied to clipboard

true if Kotlin/Native will use MainThreadFinalizerProcessor to process finalizers.

Since Kotlin 1.9
Link copied to clipboard

How many finalizers will be processed inside a single autoreleasepool.

Since Kotlin 1.9
Link copied to clipboard

How much time can each task take.

Since Kotlin 1.9
Link copied to clipboard

The minimum interval between two tasks.

Since Kotlin 1.9