Skip to content

Conversation

@wfltaylor
Copy link

@wfltaylorwfltaylor commented May 14, 2025

Currently, AsyncBufferSequence will leak the base sequence if iteration concludes without next() being cancelled. This is because the internal task retains UnboundedBufferStorage/BoundedBufferStorage causing a reference cycle. This is fixed by adopting an InternalClass inside the iterator which calls an iteratorDeinitialized() function on the storage, as done by other sequences in this package such as combine latest and merge.

The following code illustrates the issue: the assert fails meaning the channel has leaked.

letchannel=AsyncChannel<Void>()Task{forawait_in channel.buffer(policy:.bounded(1)){break}Task{[weak channel]inassert(channel ==nil)}}Task{[weak channel]inawait channel?.send(())}

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@wfltaylor@tphan158