Skip to content

Commit c0ed572

Browse files
committed
Explain potential memory leak that nulling BufferedChannelIterator.continuation out prevents
1 parent 1a09305 commit c0ed572

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,12 @@ internal open class BufferedChannel<E>(
16901690
}
16911691

16921692
fun tryResumeHasNextOnClosedChannel() {
1693-
// Read the current continuation and clean
1694-
// the corresponding field to avoid memory leaks.
1693+
/*
1694+
* Read the current continuation and clean the corresponding field to avoid memory leaks.
1695+
* This nulling out cleans up iterator's waiters (i.e. `hasNext()` callers) when the channel is closed.
1696+
* Without this cleanup, waiters will be GC-reacheable even when the channel is already closed and
1697+
* waiters are successfully resumed.
1698+
*/
16951699
val cont = this.continuation!!
16961700
this.continuation = null
16971701
// Update the `hasNext()` internal result and inform

0 commit comments

Comments
 (0)