Is it necessary to unsubscribe reactive form control's valueChanges subscription or Angular will unsubscribe it for us ?
In Router :
According to the official documentation, Angular should unsubscribe for you, but apparently, there is a bug.
So my concern here is the same for FormControl's valueChanges.
You must unsubscribe to prevent memory leaks and to avoid unexpected side-effects in your application.
🎩 Automagically Unsubscribe in Angular As you probably know when you subscribe to an observable or event in JavaScript, you usually need to unsubscribe at a certain point to release memory in the system. Otherwise, you will have a memory leak. A memory leak occurs when a section of memory that is no longer being…
Effects are the primary way of handling logic within NgRx. They allow us to observe streams of actions and react to them. We do not need to subscribe to any effect nor do you need to manually unsubscribe. That is handled internally by the NgRx Effects module; once again taking that burden out of our hands.
Since an Angular service never get's destroyed, unless your entire application get's destroyed, there is no real reason to unsubscribe from it. The observable will either complete or error or keep going as long as your application does.
Yes it is necessary, in order to not cause memory leaks with lost references to subscriptions you should always unsubscribe on ngOnDestroy. Or you could use other techniques to close the subscription when you no longer need it like takeUntil
or takeWhile
See this post for more details about unsubscribing
http://brianflove.com/2016/12/11/anguar-2-unsubscribe-observables/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With