Skip to content

Commit

Permalink
~ LeakTest for manual cyclic unlinking
Browse files Browse the repository at this point in the history
  • Loading branch information
elizarov committed Nov 11, 2019
1 parent a331182 commit 7ca7a8a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions kotlinx-coroutines-core/native/test/LeakTest.kt
Original file line number Diff line number Diff line change
@@ -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<Ref?>(this)
}

@SharedImmutable
private val nullRef = Ref()

0 comments on commit 7ca7a8a

Please sign in to comment.