ReactiveUI memory usage
Asked Answered
O

0

7

I have recently refactored an MVVM application to use ReactiveUI. Basically, I have changed a lot of the code in the ViewModels to use ReactiveLists, derived lists and ObservableAsPropertyHelpers. Once I was done, I noticed that the memory usage of this application went from 100MB to 550MB (in the exact same situation, with the same data and features).

I have a large (~3000) number of objects from the same class and using the diagnostics tools from VS, I noticed that the OAPH from this class (they are 5) used a lot of memory. At first, I assumed an issue with threading so I decided to try and reproduce the issue in a test application.

To do so I created a ViewModel:

public class ItemViewModel : ReactiveObject
{
    private ObservableAsPropertyHelper<bool> myVar1;
    public bool MyProperty1
    {
        get { return myVar1.Value; }
    }

    public ItemViewModel()
    {
        myVar1 = Observable.Return(false).ToProperty(this, x => x.MyProperty1);
    }
 }

I have removed the 3 other OAPH that are stricly identical for brievity.

My main ViewModel looks like this:

public class MainViewModel : ReactiveObject
{
    public IReactiveList<ItemViewModel> Items { get; private set; }

    public MainViewModel()
    {
        var items = new List<ItemViewModel>();
        for (int i = 0; i < 3000; i++)
        {
            items.Add(new ItemViewModel());
        }
        Items = new ReactiveList<ItemViewModel>(items);
    }
}

That's all there is in this application. If I run it, it uses 35MB. If I remove the code in the constructor of ItemViewModel, it only uses 11.5MB. So it seems to reproduce my high memory usage.

My question is: am I doing something wrong? Can ReactiveUI handle that "many" items?

Osteoclast answered 23/2, 2015 at 22:41 Comment(2)
did you get any answers? we are experiencing the same issue.Unfailing
Not yet. The issue is still open on Github : github.com/reactiveui/ReactiveUI/issues/823Osteoclast

© 2022 - 2024 — McMap. All rights reserved.