I started working with a legacy angular 6 application that is using Rxjs observables. The observables within the components don't seem to be using an unsubscribe from what I can see. Example subscribe within the ngOnInit:
this.service.getCustomerDetail(customers).subscribe(
(data) => {
this.customerData = data;
},
() => {
this.notify.addNotification(
new notification(
`Error retrieving customer data`
)
);
}
);
The subscribes are using the completion even if nothing in it aka Next, Error, Complete values of Rxjs subscribes but this to me looks like it needs to push these into subscriptions and then on the ngOnDestroy unsubscribe to all of them. Is that correct that these subscriptions without that unsubscribe even if the complete is within the observable would stay in the heap memory aka cause memory leaks?
Using the TakeUntil approach would I use the TakeUntil in the cases where my subscribe is using the error and complete sections for example:
this.service.getCustomerDetail(customers)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(data) => {
this.customerData = data;
},
() => {
//error section
this.notify.addNotification(
new notification(
`Error retrieving customer data`
)
);
},
() => {
//complete section
this.loadAddlDetail();
}
);
Thanks for any info on this.