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

Minor memory leak in Pushes that have not timed out/cancelled timeout when Channel closes #142

Open
jatindervrify opened this issue Jun 20, 2019 · 1 comment

Comments

@jatindervrify
Copy link

When performing a Push and then closing a channel, the timeout work item never releases the Push due to the strong retaining of self on Line 240 of Push.swift

/// Setup and start the Timeout timer.
let workItem = DispatchWorkItem { in
    self.trigger("timeout", payload: [:])
}

changing this closure to use [weak self] resolves the issue

/// Setup and start the Timeout timer.
let workItem = DispatchWorkItem { [weak self] in
    self?.trigger("timeout", payload: [:])
}

Screenshots:

image

image

Happy to investigate further if I'm in the wrong here. Cheers

@dsrees
Copy link
Collaborator

dsrees commented Jul 18, 2019

Finally getting around to looking into this. Turns out if you add [weak self] to the callback, then the callback is deallocated regardless unless you hold on to a reference of the Push when sending it, meaning a legit timeout won't be handled successfully.

channel
    .push("event", payload: ["foo": "bar"])
    .receive("timeout", callback: { (_) in
        timeoutCallsCount += 1
    })
                
fakeClock.tick(channel.timeout / 2)
expect(timeoutCallsCount).to(equal(0))
                
fakeClock.tick(channel.timeout)
expect(timeoutCallsCount).to(equal(1)) // <- this will be 0 if [weak self] is added

unless you hold reference to the Push

let push = channel
    .push("event", payload: ["foo": "bar"])
    .receive("timeout", callback: { (_) in
        timeoutCallsCount += 1
    })

I'll have to keep looking into this

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

2 participants