ReactiveUI ObservableAsPropertyHelper / Reactive Extensions Memory Leak?

I noticed that in my .NET 3.5 application using ReactiveUI, I have a significant memory leak, which seems to occur in ObservableAsPropertyHelper. I created a test project to demonstrate it here .

It seems that every change notification caused by the simple computed property of the ObservableAsPropertyHelper is wasting memory. It seems that the leak comes from Reactive Extensions, and not directly into ReactiveUI, but my use of OAPH is so simple that I wonder if anyone has come across this or can offer a suggested fix.

The severity of a memory leak varies between .NET 3.5 (RxUI 2.4, Rx 1.1) and .NET 4.0 (RxUI 4.2, Rx 2.0.3). This is much closer to linear with every property update in .NET 3.5. However, the leak still exists in .NET 4.0.

I downloaded a test project and some profiler images for my test session .NET 3.5 and .NET 4.0 with the test application here .

In the images you can see that the graphs of the objects are different, so we can talk about two different leaks entirely. In the 4.0 session (40_RetentionGraph.png), you can see that the most highlighted objects are Ints (my property type is OAPH) and ConcurrentQueue. It seems that there is some kind of round reference question. You can also see in 40_IntsAllocatedGCRootGrows.png that the distance from the GC root from the instances is increasing.

In version 3.5 (which bothers me the most), you can see (35_Summary.png) that the most highlighted objects are Action and ScheduledObserver. The graph of the object is a bit more complicated and differs from version 40.

I looked through this discussion but did not find a direct answer: my scenario is very simple updates for OAPH. Any understanding of possible solutions to this leak is appreciated.

+6
source share
1 answer

You did not specify a scheduler, so by default an RxUI is sent for DispatcherScheduler. Since your application is a console application, there is no dispatcher running. All this memory is consumed in the OnNext queue, and nothing to run.

You may encounter running the dispatcher and submitting its frames to run (which the WPF application will do for you), or for testing, just change the ReactiveTester constructor as follows:

public ReactiveTester() { _Total = this.WhenAny(x => xA, x => xB, (a, b) => a.Value + b.Value) .ToProperty(this, x => x.Total); } 

For this:

 public ReactiveTester() { _Total = this.WhenAny(x => xA, x => xB, (a, b) => a.Value + b.Value) .ToProperty(this, x => x.Total, 0, Scheduler.CurrentThread); } 

And everything will be just pink.

+4
source

Source: https://habr.com/ru/post/945488/


All Articles