CombineCommunity / CombineExt

CombineExt provides a collection of operators, publishers and utilities for Combine, that are not provided by Apple themselves, but are common in other Reactive Frameworks and standards.
https://combine.community
MIT License
1.73k stars 155 forks source link

Memory Leak in ReplaySubject, WithLatestFrom, and anything else that uses the DemandBuffer #139

Closed adlerj closed 2 years ago

adlerj commented 2 years ago

Repro Video Sample Project

This project is setup with ViewController -> ChildViewController -> GrandChildViewController

The leak occurs only when ChildViewController sinks to the postsSubject

It seems that if a publisher is bound somewhere else, and then that same publisher is used with a withLatestFrom a retain cycle is introduced and Combine internally crashes

Seems like the DemandBuffer doesn't correctly forward completion information upstream if the upstream Subscriber is being used somewhere else which is why we are crashing in WithLatestFrom and share(replay: 1)

adlerj commented 2 years ago

I think this might be related https://github.com/CombineCommunity/CombineExt/issues/114