Memory Leak with Navigation?
Hello,
There is what would appear to be a well known memory leak issue with Xamarin Forms (as well as Xamarin.IOS and Xamarin.Android) especially during navigation. Some references below.
At least in my experiences (which seem to be similar to many others in the community) it is literally impossible to create a downward trend in memory consumption while navigating from page to page. Removing a page from the stack NEVER removes all the memory. The Heap is perpetually growing. This can be recreated with just about any view. Using a view that contains a list that implements a custom view cell will surface the problem immediately.
Question I have is will migrating from the out-of-the-box navigation help with this or is PRISM subject to the same issues ? (making the assumption you agree with the findings listed below in terms of there being an actual memory leak issue)
http://stackoverflow.com/questions/25198762/is-this-a-memory-leak-in-xamarin-forms http://stackoverflow.com/questions/25532870/xamarin-ios-memory-leaks-everywhere https://bugzilla.xamarin.com/show_bug.cgi?id=21995 http://forums.xamarin.com/search?adv=&search=memory+leak+in+xamarin+forms&title=&author=&cat=all&tags=&discussion_d=1&discussion_question=1&comment_c=1&comment_answer=1&within=1+day&date=
I don't know if Xamarin.Forms has a memory leak or not. Given that Prism is built on top of XF, then if there was a memory leak in XF, using Prism wouldn't fix it.
Bill,
I've just opened a support ticket with Xamarin for this very issue. I can tell you that Prism doesn't stop it from happening.
Brian,
Quick question (I know this is flagged as closed but the answer may help me work with Xamarin to find the source of the problem): Should PRISM XF be creating a new viewmodel each time you navigate to the page, or should it work as a singleton, like services do with Unity? In tracing things I'm finding that every time I navigate to a page the viewmodel constructor is being called. That's OK if when I navigate away from the page the previous instance of the ViewModel is released, but using Xamarin's (significantly buggy) profiler I don't seem to be getting anything back when I leave the page, even if I force a garbage collection afterwards.
I just don't want Xamarin to come back and point fingers saying it's because prism keeps instantiating VM after VM.
I'm happy to take point on this issue as far as coordinating anything with Xamarin if needed.
Jeff
Just to add I created a test project using the latest Prism XF with two pages, each having a binding for a label, and single button calling a delegate command to navigate to the other page and a small image. Just clicking the buttons to navigate back and forth between the two pages will crash the app in about two minutes as memory climbs with each click.
I've sent a copy of the solution to Xamarin Support and will update this with what they find.
Each time you navigate to a page, the page is created and the VM is then created. It will not recreate the VM when going back to the page via a GoBack call. Only when navigating to the page. We do not provide page caching yet as there are a number of issues that have to be solved first. Namely, a page instance cannot exist in the stack twice. So a new page instance must be created when navigating to a page. So if caching, should we automatically remove the page from it's previous position in the stack (which stack) and the add it at the end? Maybe, maybe not. As you can see, this it just the tip of the iceberg.
Each time you navigate to a page, the page is created and the VM is then created. It will not recreate the VM when going back to the page via a GoBack call. Only when navigating to the page. We do not provide page caching yet as there are a number of issues that have to be solved first. Namely, a page instance cannot exist in the stack twice. So a new page instance must be created when navigating to a page. So if caching, should we automatically remove the page from it's previous position in the stack (which stack) and the add it at the end? Maybe, maybe not. As you can see, this it just the tip of the iceberg.
Hi Brian, I'd like to ask if maybe you are aware if anything was done in this topic?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.