We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1a09305 commit 04bab1dCopy full SHA for 04bab1d
kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt
@@ -1690,8 +1690,11 @@ internal open class BufferedChannel<E>(
1690
}
1691
1692
fun tryResumeHasNextOnClosedChannel() {
1693
- // Read the current continuation and clean
1694
- // the corresponding field to avoid memory leaks.
+ /*
+ * Read the current continuation of the suspended `hasNext()` call and clean the corresponding field to avoid memory leaks.
1695
+ * While this nulling out is unnecessary, it eliminates memory leaks (through the continuation)
1696
+ * if the channel iterator accidentally remains GC-reachable after the channel is closed.
1697
+ */
1698
val cont = this.continuation!!
1699
this.continuation = null
1700
// Update the `hasNext()` internal result and inform
0 commit comments