-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
~ LeakTest for manual cyclic unlinking
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |