mseemann / angular2-mdl-ext

Additional components for @angular-mdl/core that are not part of material design lite (npm: @angular-mdl/*)
MIT License
99 stars 42 forks source link

Unclosed Subscription memory leak #814

Closed hotforfeature closed 7 years ago

hotforfeature commented 7 years ago

Maybe I'm missing something, but in https://github.com/mseemann/angular2-mdl-ext/blob/master/src/components/datepicker/datepicker.service.ts#L37 you're returning a Subject as an observable, and when the dialog is hidden you provide the value to the subject using Subject.next().

Are subscriptions to selectDate().subscribe(() => {}) supposed to be re-used? The documentation indicates that every time I want a new date, I should call selectDate() again, rather than re-use a subscription. This will result in a bunch of open subscriptions being created if you keep calling selectDate(), which is a memory leak.

I would expect the subject to immediately complete after getting the date:

    pDialog.subscribe( (dialogReference: MdlDialogReference) => {
     dialogReference.onHide().subscribe( (date: Date) => {
       subject.next(date);
       subject.complete(); // close the current subscription to selectDate()
     });
    });
mseemann commented 7 years ago

hi thx for pointing me out to this problem. will be fixed asap.

mseemann commented 7 years ago

fixed in @angular-mdl/datepicker:0.0.3