opsb
(Oliver Searle-Barnes)
1
I'm trying to understand how subjects are supposed to clean up references to subscriptions when they cancel. Looking at OpenCombine's implementation of CurrentValueSubject I see that there's a _subscriptions property which keeps track of the current subscriptions. I can see that they're appended in the receiveSubscriber callback. Where I'm a bit lost is that these subscriptions never seem to be removed. The subscription itself nullifies it's reference to the subject at OpenCombine/CurrentValueSubject.swift at master · OpenCombine/OpenCombine · GitHub but the subject doesn't even seem to be notified. Do the subscriptions just stick around after they're cancelled or are they cleaned up somehow?
mayoff
(Rob Mayoff)
2
OpenCombine's implementation of CurrentValueSubject leaks subscriptions. CombineX and Apple Combine clean them up properly.
The proper subscription handling in OpenCombine is a work in progress.
1 Like
opsb
(Oliver Searle-Barnes)
4
Right, that makes sense then :) Thought perhaps there was some magic going on that I wasn't seeing.
opsb
(Oliver Searle-Barnes)
5
Thanks, will take a look at the implementation and see how it's done, I'm guessing the subject needs to be passed into the subscription.
opsb
(Oliver Searle-Barnes)
6
So I was right, but the type erasure certainly makes the implementation more involved than you might expect.
I'm happy to share the good news: the issue with leaking subscriptions in OpenCombine has been fixed in the master branch.
1 Like