Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak issue with PassthroughRelay #167

Open
just1103 opened this issue Feb 10, 2024 · 0 comments
Open

Memory leak issue with PassthroughRelay #167

just1103 opened this issue Feb 10, 2024 · 0 comments

Comments

@just1103
Copy link

Hello everyone,

I've been using CombineExt extensively in my projects and found it incredibly valuable.
Recently, I encountered a memory leak issue with PassthroughRelay. Upon replacing it with PassthroughSubject, the retain cycle disappeared.

It appears that PassthroughRelay fails to release its subscriptions upon receiving completion, as similarly described in this PR #85.

I've come up with a potential solution for this issue and confirmed its resolution in my project, but I'm not fully proficient with Combine. So, any comments or suggestions would be greatly appreciated.


Original Subscription’s cancel method:

func cancel() {
    sink = nil
}

Solution:

// Call forceFinish() in Subscription’s cancel method. 
// And add self.sink = nil in forceFinish method.

func forceFinish() {
    self.sink?.shouldForwardCompletion = true
    self.sink?.receive(completion: .finished)
    self.sink = nil // added
}

func cancel() {
    forceFinish() // replaced
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant