@NativeRuntimeApi object GC
Note: this API is unstable and may change in any release.
Kotlin/Native uses tracing garbage collector (GC) that is executed periodically to collect objects that are not reachable from the "roots", like local and global variables. See documentation to learn more about Kotlin/Native memory management.
This object provides a set of functions and properties that allows to tune garbage collector.
Legacy memory manager
Kotlin/Native relies upon reference counting for object management, however it could not collect cyclical garbage, so we perform periodic garbage collection. This may slow down application, so this interface provides control over how garbage collector activates and runs. Garbage collector can be in one of the following states:
If true update targetHeapBytes after each collection.
var autotune: Boolean
Deprecated and unused.
var collectCyclesThreshold: Long
Deprecated and unused.
var cyclicCollectorEnabled: Boolean
Returns statistics of the last finished garbage collection run. This information is supposed to be used for testing and debugging purposes only
val lastGCInfo: GCInfo?
The maximum value for targetHeapBytes. Only used if autotune is true. See targetHeapBytes for more details.
var maxHeapBytes: Long
The minimum value for targetHeapBytes Only used if autotune is true. See targetHeapBytes for more details.
var minHeapBytes: Long
When Kotlin code is not allocating enough to trigger GC, the GC scheduler uses timer to drive collection. Timer-triggered collection will happen roughly in regularGCInterval .. 2 * regularGCInterval since any previous collection. Unused with on-safepoints GC scheduler.
var regularGCInterval: Duration
Total amount of heap available for Kotlin objects. When Kotlin objects overflow this heap, the garbage collection is requested. Automatically adjusts when autotune is true: after each collection the targetHeapBytes is set to heapBytes / targetHeapUtilization and capped between minHeapBytes and maxHeapBytes, where heapBytes is heap usage after the garbage is collected. Note, that if after a collection heapBytes > targetHeapBytes (which may happen if autotune is false, or maxHeapBytes is set too low), the next collection will be triggered almost immediately.
var targetHeapBytes: Long
What fraction of the Kotlin heap should be populated. Only used if autotune is true. See targetHeapBytes for more details.
var targetHeapUtilization: Double
GC threshold, controlling how frequenly GC is activated, and how much time GC takes. Bigger values lead to longer GC pauses, but less GCs. Usually unused. For the on-safepoints GC scheduler counts how many safepoints must the code pass before informing the GC scheduler.
var threshold: Int
How many bytes a thread can allocate before informing the GC scheduler.
var thresholdAllocations: Long
Trigger new collection and wait for its completion.
fun collect()
Deprecated and unused.
fun collectCyclic()
Deprecated and unused. Always returns null.
fun detectCycles(): Array<Any>?
Deprecated and unused. Always returns null.
fun findCycle(root: Any): Array<Any>?
Deprecated and unused.
fun resume()
Trigger new collection without waiting for its completion.
fun schedule()
Deprecated and unused.
fun start()
Deprecated and unused.
fun stop()
Deprecated and unused.
fun suspend()
© 2010–2023 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.runtime/-g-c/index.html