I have an Angular form array of groups. Elsewhere in the app some subscriptions are setup on formcontrol validation changes. At some point in the life cycle I delete a formgroup. Do I need to be concerned that subscriptions are still open on objects that arent in memory anymore?
NO
If you call .subscribe anywhere in your code, the only way to not leak memory is to make sure those subscriptions gets unsubscribed again.
You need to either manually unsubscribe each one or make sure the observables you subscribe to are all finite - meaning they have an "end" signal somewhere. They can be either a limited sequence (.first(), .take(), etc) or they can be toggled off by ending in a .takeWhile() or .takeUntil()
The subscriptions does not care if you leave scope, remove referenced object or even navigate away. You need to make sure they get unsubscribed.
See my answer here: RXJS - Angular - unsubscribe from Subjects
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments