Skip to content

Commit 7ca7a8a

Browse files
committed
~ LeakTest for manual cyclic unlinking
1 parent a331182 commit 7ca7a8a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)