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?

Askolein
  • 3,250
  • 3
  • 28
  • 40
Damien Chaib
  • 401
  • 3
  • 14

0 Answers0