Skip to content

Commit 878c114

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

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 is required to unbind iterator's waiters (e.g. `hasNext()` callers)
1696+
* from the iterator in case when a channel is closed, continuation is sucessfulluy resumed
1697+
* with closed token (false|exception), but iterator is still reachable for any reason.
1698+
*/
16951699
val cont = this.continuation!!
16961700
this.continuation = null
16971701
// Update the `hasNext()` internal result and inform

0 commit comments

Comments
 (0)