We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a331182 commit 7ca7a8aCopy full SHA for 7ca7a8a
kotlinx-coroutines-core/native/test/LeakTest.kt
@@ -0,0 +1,34 @@
1
+/*
2
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+package kotlinx.coroutines
6
7
+import kotlin.test.*
8
+import kotlin.native.concurrent.*
9
10
+/**
11
+ * Test manual memory management by unlinking cycle.
12
13
+class LeakTest {
14
+ @Test
15
+ fun testLeak() {
16
+ // create obj1 <-> obj2 cycle
17
+ val obj1 = Ref()
18
+ val obj2 = Ref()
19
+ obj1.ref.value = obj2
20
+ obj2.ref.value = obj1
21
+ // freeze it
22
+ obj1.freeze()
23
+ // break the cycle
24
+ obj1.ref.value = nullRef
25
+ obj2.ref.value = nullRef
26
+ }
27
+}
28
29
+private class Ref {
30
+ val ref = FreezableAtomicReference<Ref?>(this)
31
32
33
+@SharedImmutable
34
+private val nullRef = Ref()
0 commit comments