8
votes

I am developing a windows 8 Native App. My app is getting crash after going back and forth in the application for sometime. On Analysis, using the memory profiler i found that each time i navigate from one page to another the memory usage increases inspite of me setting null all the objects of list, webclient, string and so on to null and calling GC.Collect after that on the NavigatedFrom Event.

Firstly i thought it would be due to the images and hence i removed the images from the app and tested but still there is no change in the memory usage of the app. Somehow the GC.Collect isn't working and freeing the memory.

I have tried the below mentioned things but to my bad luck isnt working to release the memory, instead the result remains the same.

  • I have set the image urisource to null before setting the new source and then call gc.Collect to free the memory usage but it does not seem to release it

  • Secondly , I have set all the objects to null, and call GC.Collect() but still it does not free up the space from the memory usage of the phone app.

  • I also tried to analyze using the memory profiler but I am not able to track anything.

I have also gone through all the post and implemented the suggested things but the GC.Collect() doesnt seem to release the memory.

Is there any work around for the following issue.How can i free the memory consumed on navigating from one page to another?

1
It's not likely that you'll get an answer on this. Try to make a minimal program that reproduces the error. Or dig deeper with the profiler. - Henk Holterman
Make sure you are using "using" statements for IDisposable objects. - Polyfun
It's weird that you still have the issue after removing the picture, it is usually the number one source of leaks on Windows Phone. How are you navigating from one page to another? Are you always using NavigationService.Navigate or do you sometimes use NavigationService.GoBack? A page is kept in memory as long as it's in the backstack. - Kevin Gosse
I am using NavigationService.Navigate from one page to another and back. Is there any way to remove the page from memory explicitly? - user2728319
Did tou ever find a solution? - JTIM

1 Answers

3
votes

Seems like something is preventing the objects from being recycled by the garbage collector in some cycle. This could be, and normally is, due to some events handlers not being removed, thus mantaining the object alive.

If you have any event in the page or the viewmodel, or any object within the page, remove it (-=) in the onNavigatedFrom method prior to exit the page... This maybe do the trick and your page memory is free....