TransferMode

Note: modern Kotlin/Native memory manager allows to share objects between threads without additional ceremonies, so TransferMode has effect only in legacy memory manager.

Object Transfer Basics.

Objects can be passed between threads in one of two possible modes.

  • SAFE - object subgraph is checked to be not reachable by other globals or locals, and passed if so, otherwise an exception is thrown

  • UNSAFE - object is blindly passed to another worker, if there are references left in the passing worker - it may lead to crash or program malfunction

Safe mode checks if object is no longer used in passing worker, using memory-management specific algorithm (ARC implementation relies on trial deletion on object graph rooted in passed object), and throws an IllegalStateException if object graph rooted in transferred object is reachable by some other means,

Unsafe mode is intended for most performance critical operations, where object graph ownership is expected to be correct (such as application debugged earlier in SAFE mode), just transfers ownership without further checks.

Note, that for some cases cycle collection need to be done to ensure that dead cycles do not affect reachability of passed object graph.

Since Kotlin

1.3

See also

Entries

Link copied to clipboard

Reachability check is performed.

Link copied to clipboard

Skip reachability check, can lead to mysterious crashes in an application. USE UNSAFE MODE ONLY IF ABSOLUTELY SURE WHAT YOU'RE DOING!!!

Properties

Link copied to clipboard

Returns a Java Class instance of the enum the given constant belongs to.

Since Kotlin 1.7
Link copied to clipboard

Returns a representation of an immutable list of all enum entries, in the order they're declared.

Since Kotlin 1.3
Link copied to clipboard
Since Kotlin 1.3
Link copied to clipboard
Since Kotlin 1.3
Link copied to clipboard
val value: Int
Since Kotlin 1.3

Functions

Link copied to clipboard
infix inline fun <T> Comparable<T>.compareTo(other: T): Int

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it's less than other, or a positive number if it's greater than other.

Since Kotlin 1.6
Link copied to clipboard

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Since Kotlin 1.3
Link copied to clipboard

Returns an array containing the constants of this enum type, in the order they're declared.

Since Kotlin 1.3