GC class sealed

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:

  • running
  • suspended (so cycle candidates are collected, but GC is not performed until resume)
  • stopped (all cyclical garbage is hopelessly lost) Immediately after startup GC is in running state. Depending on application needs it may select to suspend GC for certain phases of its lifetime, and resume it later on, or just completely turn it off, if GC pauses are less desirable than cyclical garbage leaks.
Annotations

Properties

autotune Boolean
If true update targetHeapBytes after each collection.
getter/setter pair
collectCyclesThreshold Long
getter/setter pair
cyclicCollectorEnabled Boolean
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
heapTriggerCoefficient Double
The GC is scheduled when Kotlin heap overflows heapTriggerCoefficient * targetHeapBytes.
getter/setter pair
lastGCInfo GCInfo?
Returns statistics of the last finished garbage collection run.
final
maxHeapBytes Long
The maximum value for targetHeapBytes.
getter/setter pair
minHeapBytes Long
The minimum value for targetHeapBytes.
getter/setter pair
pauseOnTargetHeapOverflow Boolean
If true, the GC will pause Kotlin threads when Kotlin heap overflows targetHeapBytes and will resume them only after current GC is done.
getter/setter pair
regularGCInterval Duration
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.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
targetHeapBytes Long
Total amount of heap available for Kotlin objects.
getter/setter pair
targetHeapUtilization Long
What fraction of the Kotlin heap should be populated.
getter/setter pair
threshold Int
getter/setter pair
thresholdAllocations Long
getter/setter pair

Methods

collect() → void
Trigger new collection and wait for its completion.
collectCyclic() → void
detectCycles() Array<Any>?
findCycle(Any root) Array<Any>?
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resume() → void
schedule() → void
Trigger new collection without waiting for its completion.
start() → void
stop() → void
suspend() → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited