commonMain.algorithms.FakeWeakRef.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weak Show documentation
Show all versions of weak Show documentation
Weak references and maps for Kotlin Multiplatform
The newest version!
package opensavvy.pedestal.weak.algorithms
import opensavvy.pedestal.weak.ExperimentalWeakApi
import opensavvy.pedestal.weak.WeakRef
/**
* Fake implementation of [WeakRef].
*
* Instead of being freed by the garbage-collector, this implementation is only
* freed when [clear] is called.
*
* Use this implementation to help trigger edge cases in algorithms that use weak references.
*/
@ExperimentalWeakApi
class FakeWeakRef(
value: T
) : WeakRef {
private var value: T? = value
override fun read(): T? =
value
fun clear() {
value = null
}
}