0

I'm still fighting with memory leak. Using improved MemoryDiagnosticsHelper, i added possibility to make datastamps to see immediate memory cunsumption.

Problem starts at full app: i have a pivot with 3 items, 2 of them containing list of 10-20 objects (with possibility to jump to item details). Memory diagnostic shows, that it consumes about 50Mb of memory. After jumping to detail page and returning to pivot, memory consumption easily grows to 70Mb.

At first, i moved list to separate app. Without style, it takes 15 Mbs. I didnt check yet, but i assume, 2 lists in pivot would take about 20Mbs, because dlls are already loaded.

So, i decided to go deeper into app loading stage.

  • At the InitializePhoneApplication(), it takes 7 Mb.
  • At the CompleteInitializePhoneApplication(), it takes 8.5 Mb with empty ViewModelLocator, or 10.5 Mb with all viewmodels. Quite large, but i have 30-40 dataservices and 40-50 viewmodels. So let it be, i'd feel myself pretty ok, if it would not grow anymore.
  • At the first page's OnNavigatedTo(), it takes almost the same, kinda 10.7 Mb with all VMs, that's ok.
  • ???
  • No profit. Seriously, what happens next? I cant see, what exactly is going on next, but MemoryDiagnosticsHelper says, that memory consumption jumps to 30 Mbs. Why? All dlls and VMs are already loaded. I'm just loading a very empty page, totally white.

Profiler (running in release mode, of course), is also helpless. It just shows growth in memory consumption, but it happens in non-managed memory. It annoys alot, really.

enter image description here

Ok, lets make question more clean. What happens next, when app is initialized (passed initialization, and viewmodel loaded and attached, and page passed OnNavigatedTo())?

EDIT 1: in the night, i got and idea, that the only weak part in my app (at least, that master-detail pages) is MVVMLight's EventToCommand. Almost first article in google is http://atomaras.wordpress.com/2012/04/23/solving-mvvmlights-eventtocommand-memory-leak-wp7/ Anybody knows, if it is alreasy fixed? I checked MvvmLight's blog, and looking like Laurent is working on installer for now. That pushes me to idea, that this leak should be already solved, isnt it?

EDIT 2: i see 2 solutions for leaking problem: either to use fix from the link above, or call commands from the codebehind. Or use another MVVM lib.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64
  • I'm not sure I understand what the problem is. Basically, are you complaining that the memory doesn't go down after you go back from details page, or are you complaining about the amount of memory used? – Kevin Gosse Oct 04 '13 at 06:23
  • Both, actually. First it the reason: when i'm jumping between master-details pages, amount of memory is growing. Not that fast, at the first glance it seems okay (kinda master (50), details(35), master(50), details(37), master(53), details(35), master(55), and so on). At first, i assumed that it is temporary stuff, but amount of used memory on the master page growth steadily. Second is consequence: when i tried to look inside, on the the used amount of memory at every moment of time, i saw that after whole app is loaded, there's still notable memory consumption jump, even with empty page. – Vitalii Vasylenko Oct 04 '13 at 07:22
  • 1
    @VitaliiVasylenko Last time I used EventToCommand from MvvmLight on windows phone (which was a couple month ago) the leak was still there, an easy fix is just to use i:InvokeCommandAction from namespace xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" which don't have this problem – Benoit Catherinet Oct 04 '13 at 11:08
  • @BenoitCatherinet Great! I was going to move commands calls to codebehind, but your fix is much faster. – Vitalii Vasylenko Oct 04 '13 at 11:17
  • @BenoitCatherinet Is there analogue of EventToCommand's PassEventArgsToCommand ? I found several solutions like http://stackoverflow.com/questions/13565484/how-can-i-pass-the-event-argument-to-a-command-using-triggers and https://github.com/jlaanstra/Windows.UI.Interactivity/pull/14 but i guess, they would be quite slow. I'm still thinking, that at least in cases PassEventArgsToCommand it would be more effective just to move command call to codebehind. What would you recommend? – Vitalii Vasylenko Oct 05 '13 at 09:59
  • 1
    I would agree that if you need to pass the event args, using codebehind in that case seem like a good solution since anyway event args are UI related so should probably not be passed to the view model instead it's probably best to handle the event in codebehind and pass to your view model something a little more abstracted. – Benoit Catherinet Oct 06 '13 at 00:55

1 Answers1

0

References.

I expected them to be loaded smoothier, during first stages of app init. Also, now it is clear, why profiler said that there's not that much managed code in the memory.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64