Should I call Dispose on Reactive Extensions (Rx) Subject <T>

I use the Reactive Extensions (Rx) object as a direct replacement for C # events, for example:

public class MyClass { private Subject<string> subject; public IObservable<string> WhenSomethingHappened { get { return this.subject.AsObservable(); } } private void OnSomethingHappened(string something) { this.subject.OnNext(something); } } 

Please note that I never call OnCompleted on my topic. Should MyClass implement IDisposable and call this.subject.Dispose? This means that any implementation using Subject must implement IDisposable.

The reason I ask is because the IDisposable template is a bit like a disease, if one thing implements it, all that uses it should also implement it.

+7
c # system.reactive
source share
1 answer

No, you really don't need to do this. When you are worried about memory usage and lifetime, think about disposing of a subscription, not about the subjects.

+10
source share

All Articles