From 7ca7a8a51090f560ad6a2756ced0dadb23398701 Mon Sep 17 00:00:00 2001 From: Roman Elizarov Date: Mon, 11 Nov 2019 22:18:15 +0300 Subject: [PATCH] ~ LeakTest for manual cyclic unlinking --- .../native/test/LeakTest.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 kotlinx-coroutines-core/native/test/LeakTest.kt diff --git a/kotlinx-coroutines-core/native/test/LeakTest.kt b/kotlinx-coroutines-core/native/test/LeakTest.kt new file mode 100644 index 0000000000..f6e5b412a2 --- /dev/null +++ b/kotlinx-coroutines-core/native/test/LeakTest.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +package kotlinx.coroutines + +import kotlin.test.* +import kotlin.native.concurrent.* + +/** + * Test manual memory management by unlinking cycle. + */ +class LeakTest { + @Test + fun testLeak() { + // create obj1 <-> obj2 cycle + val obj1 = Ref() + val obj2 = Ref() + obj1.ref.value = obj2 + obj2.ref.value = obj1 + // freeze it + obj1.freeze() + // break the cycle + obj1.ref.value = nullRef + obj2.ref.value = nullRef + } +} + +private class Ref { + val ref = FreezableAtomicReference(this) +} + +@SharedImmutable +private val nullRef = Ref() \ No newline at end of file