This seems to work and I am curious to know if this is safe. Take the following scenario...
In a shared service class I have:
this.subject = new Rx.Subject();
Lets say this observable has multiple subscribers.
The subject looks like so subject.observers = [Subscriber 1, Subscriber 2...Subscriber n]
If I wanted the Subject
to stop notifying all subscribers, I know I can do subject.unsubscribe()
and that will set subject.observers = null
, but this then does not allow any future subscribers to attach to the this.subject
instance.
Okay heres the question...
Instead of using subject.unsubscribe()
, can I just clear out the observers array like so subject.observers.length = 0
with out causing any issues?
This then clears out all of the subscribers it was watching but still allows me to attach other subscribers in the future.
I can iterate through the subject.observers
array and unsubscribe that way, but if I just clear out the observers array with out causing any memory leaks, I'd prefer the way.