• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 import kotlinx.coroutines.*
5 import kotlinx.coroutines.test.*
6 import kotlin.test.*
7 
8 class MemoryLeakTest {
9 
10     @Test
<lambda>null11     fun testCancellationLeakInTestCoroutineScheduler() = runTest {
12         val leakingObject = Any()
13         val job = launch(start = CoroutineStart.UNDISPATCHED) {
14             delay(1)
15             // This code is needed to hold a reference to `leakingObject` until the job itself is weakly reachable.
16             leakingObject.hashCode()
17         }
18         job.cancel()
19         FieldWalker.assertReachableCount(1, testScheduler) { it === leakingObject }
20         runCurrent()
21         FieldWalker.assertReachableCount(0, testScheduler) { it === leakingObject }
22     }
23 }
24