cvuorinen / angular1-async-filter

Angular2 async pipe implemented as Angular 1 filter to handle promises & RxJS observables
MIT License
59 stars 6 forks source link

should subscriptions be disposed when the scope is destroyed? #1

Closed sirbarrence closed 8 years ago

sirbarrence commented 8 years ago

Currently the filter seems to keep references to subscriptions forever, even after the given scope is destroyed. Also the last value emitted by each observable is stored forever. It seems like this could at the very least lead to some memory leaks, depending on the application size and the size of the values.

At worst, the observable's lifetime could be longer than the scope's. If the observable keeps sending values after the scope is destroyed, the filter could try to call $asyncApply() on the now-destroyed scope, which would probably throw an error.

About to submit a pull request to attempt to address this.

cvuorinen commented 8 years ago

Yes, this is something I was aware, just haven't gotten around to addressing it yet. I have been looking into using WeakMap for holding the reference to the observables, but I'm not really sure if that would make any difference if there is an active subscription. Need to experiment with this a bit, since don't really have experience with WeakMap. Thanks for your input and raising this issue, I'll look into it.