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 #31

Closed
ApolloZhu opened this issue Feb 17, 2019 · 5 comments
Closed

Memory Leak #31

ApolloZhu opened this issue Feb 17, 2019 · 5 comments

Comments

@ApolloZhu
Copy link
Contributor

ApolloZhu commented Feb 17, 2019

I noticed this library is leaking RunLoopTask:

image

and can be reproduced with this trivial macOS example:

class ViewController: NSViewController {
    var task: Task?
    @IBAction func onButtonPress(_ sender: Any) {
        task = Plan.after(Interval(seconds: 2)).do {
            print("Hi")
        }
    }
}
@luoxiu
Copy link
Owner

luoxiu commented Feb 17, 2019

Hi, @ApolloZhu , thanks for your feedback. I just pushed a commit and hope it will fix the problem.

@luoxiu
Copy link
Owner

luoxiu commented Feb 17, 2019

I'm working on 2.x branch now, and hopefully, I will release 2.0 with this today!

@ApolloZhu
Copy link
Contributor Author

ApolloZhu commented Feb 17, 2019

This fix requires manually invoke task.cancel(). Is that intended behavior?

I suppose not, since then examples in README will cause memory leaks.

@luoxiu
Copy link
Owner

luoxiu commented Feb 17, 2019

...
Yes. I thought you were talking about the memory leak caused by an object reference being caught by a closure.
Yes, if a task is no longer being used, you should call its cancel method to release it. I wrote it here). Sorry, my intention is to make it consistent with the timer experience(timer.invalidate()), but I also realized that it seems a bit misleading to users.
I am doing some refactoring now and may redesign this part of the api.

@ApolloZhu
Copy link
Contributor Author

Thanks for the explanation and sorry for not providing enough context in the previous comment.

@luoxiu luoxiu closed this as completed Feb 17, 2019
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