Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ReactiveUI leak subscriptions?

I've looked at the examples of ReactiveUi from the blogs and I am left wondering if ReactiveUI has some sort of subscription management facility underneath or are the examples ignoring the fact that they might leak subscriptions?

Any time I call a method in ReactiveUi that results in an IDisposable, do I need to hold onto that reference and track it myself? Also does this mean my ViewModels need to be disposable, this seems difficult since we don't really know when the connected "Views" go away (i.e. if my ViewModel reflects items in a data grid) in WPF so there seems to be no appropriate place to call dispose.

like image 320
Damian Avatar asked Jan 18 '12 20:01

Damian


1 Answers

You also have to remember, that the IDisposables returned by Rx and ReactiveUI aren't associated with unmanaged memory - it's all just simple .NET objects, still ref'ed by the garbage collector.

Most of the Subscriptions you make in the constructors of your ReactiveObjects will be tied to the lifetime of the host object - so when it goes out of scope and is subject to GC, so will all the subscriptions, the CLR will detect the circular reference and just nuke everything.

As Enigmativity mentions, the one tricky bit is when you use FromEventPattern to tie the lifetime of a Subscription (and perhaps, a ViewModel) to the lifetime of a WPF object. However, I'd argue if you're using FromEventPattern often in ReactiveUI, you are most definitely Doing It Wrong™.

RxUI is all about ViewModels, and ViewModels are all about commands and properties (and wiring up how properties are related to each other), so you can test the behavior of user experience separately from its visuals.

like image 114
Ana Betts Avatar answered Nov 12 '22 05:11

Ana Betts