1
votes

I am suffering from a memory leap within my WP8 app.
I have investigated and narrowed the problem down though I would like some guidance on where to go next. I do have a hunch that the Pivot and LongListSelector are the cause, described below.

Problem Description: App browses across numerous pages (typically a few dozen). Memory use is increasing by around 2-4MB per page and not being fully released. After around 25 pages memory use has increased from 30MB to 90MB.

Existing Code: I am already performing some cleanup on each page before navigating to the next. I am also already calling NavigationService.RemoveBackEntry() to keep the Back Stack small.

Investigation: I have used the Memory Profiler which reveals about 15MB of the growth is my own data that isn't being cleaned up. The remaining 40-50MB is not included in the Heap Summary (i.e. the total only comes to about 15MB out of the observed 90MB). I will work on the 15MB, but since it doesn't appear to be the most significant factor, I would like some guidance on sensible next steps.

Possible Cause: I have another set of pages (again typically a few dozen pages when browsed) composed of very similar content. These pages however do NOT show the same problem. Memory use remains low throughout. Both sets of pages use similar cleanup code when navigating. One key difference is the affected pages use a Pivot control, each of which has a 3 or 4 Pivot Items, a couple of which contain LongListSelectors. The LongListSelectors are data bound to Generic Lists generated at run time. No images, only text. Not especially long lists, 20 or so items in each. I have come across a couple of posts vaguely suggesting that this combination of controls is susceptible to memory leaks. I commented the code that populates these controls, and sure enough, memory use now peaks at around 50-60MB.
It may be even lower if I remove the controls completely (I haven't tested that yet). So, these controls are not the whole story, but clearly are a large part of the problem.

Question: Is there a known issue with these controls (LongListSelector, Pivot)? Should there be some code used to clean up these controls? I have tried setting the list ItemSource to an empty list, but this had no effect on the memory growth. Is there any way to workaround it? (obviously changing the type of controls used is one option).

Thanks for reading.

2
Could you post xaml and code behind for the LongListSelector and Pivot? Without any code this is difficult to troubleshoot. - philorube
I have investigated further and found a workaround - see cbailiss.wordpress.com/2014/01/24/… - cbailiss

2 Answers

2
votes

After some investigation, I have found what looks like a problem with the LongListSelector recovering memory when it is cleaned up.

I have posted more details and a workaround here:

http://cbailiss.wordpress.com/2014/01/24/windows-phone-8-longlistselector-memory-leak/

0
votes

I had a same problem. All I did just changed source List<>s to ObservableCollection<>s, and then on SelectedItem changing I clearing source collection which is not visible at the moment.