You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem.Reactive;usingSystem.Reactive.Subjects;namespaceDemo;internalsealedclassTest{privateIObservable<Unit>_eventTriggered=newSubject<Unit>();publicvoidRun(){usingvarfoo=CreateFoo();// ...}privateFooCreateFoo(){varfoo=newFoo();_eventTriggered.Subscribe(_ =>{// If the following line is commented, then no report of IDISP011:foo.Dispose();});returnfoo;// IDISP011: Don't return disposed instance}sealedclassFoo:IDisposable{publicvoidDispose(){/* ... */}}}
foo can be disposed in two places: by the owner (for example, inside Run() method), or by some event, triggered somewhere else.
N.B.: Ignore other reports of IDISP004 or IDISP008, this is an example for IDISP011 only.
The text was updated successfully, but these errors were encountered:
Why Dispose it in the .Subscribe if it has to be disposed anyhow. What if the Observable doesn't fire (or fires multiple times)?
Observable is an optional route in my case (particularly, it handles item removal from the list, if requested by a user), and normally the item is being disposed when the owner disposes the list where all Foos are contained.
Disposing the same item multiple times isn't a problem, since
the owner got notified about its item disposal and then it removes it from its list
the disposal method is safe for calling it multiple times. In my case it has IsDisposed flag to handle that.
IDisposableAnalyzers version: 4.0.7
I have a scenario similar to this:
foo
can be disposed in two places: by the owner (for example, insideRun()
method), or by some event, triggered somewhere else.N.B.: Ignore other reports of IDISP004 or IDISP008, this is an example for IDISP011 only.
The text was updated successfully, but these errors were encountered: