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

Bug: Observable.removeObserver can cause a (usually minor) memory leak #10

Closed
raquo opened this issue Oct 6, 2018 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@raquo
Copy link
Owner

raquo commented Oct 6, 2018

Adding an Observer to an Observable requires you provide an Owner, and produces a Subscription. Normally the owner should take care of killing this subscription, but you can also kill it manually before the owner decides to do that.

The right way to do this is to call subscription.kill().

However, Airstream also provides a removeObserver(observer) method on Observable. While it does correctly remove the observer from the observable, it does not call subsription.kill() because it has no reference to the subscription. This means the Owner continues to keep a reference to the subscription (and thus to both observable and observer) until the Owner decides to kill them.

This is an error in my API design, and is contrary to users expectations. I will fix this one way or another, likely by removing the removeObserver method. However, the exact solution depends on how I decide to implement raquo/Laminar#33.

For now, avoid using the removeObserver method in favour of subscription.kill

@raquo raquo added the bug Something isn't working label Oct 6, 2018
@raquo raquo changed the title Bug: removeObserver can cause a (usually minor) memory leak Bug: Observable.removeObserver can cause a (usually minor) memory leak Oct 6, 2018
@raquo raquo closed this as completed in 13a47bd Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant