lbugnion / mvvmlight

The main purpose of the toolkit is to accelerate the creation and development of MVVM applications in Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Windows 10 UWP, Windows Presentation Foundation (WPF), Silverlight, Windows Phone.
http://www.mvvmlight.net
MIT License
1.17k stars 310 forks source link

Android Navigation Memory Leak #19

Open bstahlman opened 6 years ago

bstahlman commented 6 years ago

Hello @lbugnion

I have been working through some performance issues with our MVVM Light app and noticed that the Heap Size seems to forever increase in Android. At first I assumed that this was an issue in our implementation of the MVVM Light architecture, but after doing some testing with the NavigrationDroid.sln, from MVVM Light Navigation Sample I suspect that the issue may lie within the MVVM Light framework.

When debugging the sample application above, the Heap Size starts around 10MB. From there the Heap Size will increase with each click of "Navigate to Page 2 with Parameter" and "Go back to Page 2". I am bench marking these values using the DDMS tool provided with Visual Studio 2015. I also had a colleague verify similar results using a Xamarin profiler with Visual Studio 2017.

Here is the Heap from DDMS when the NavigrationDroid.sln app is first deployed to a Motorola G5 phone. image

After clicking through the navigation buttons for 1 minute (roughly 90 clicks) and clicked "Cause GC" within DDMS, here is the Heap: image

Next I let the app rest for 1 minute, and proceeded with the same test. I clicked the navigation buttons for 1 minute (roughly 90 clicks) and clicked "Cause GC" within DDMS, here is the heap: image

Would you have any idea about what is causing the Heap Size to continue to grow? I have been experimenting with unbinding the click events for each button using the OnStop/OnResume methods in Android but have not had much luck. Any advice or insight into this issue is greatly appreciated!

Thanks,

Bill

bstahlman commented 6 years ago

@lbugnion any thoughts on this? I am just curious if this is expected behavior or if you've seen it before?

MSalas95 commented 5 years ago

Did you solve this issue?

bstahlman commented 4 years ago

@lbugnion we are continuing to see issues with the memory profile of the app when running Android. The only way we are able to reduce the memory footprint is to explicitly call Finish() after navigating. Are you aware of this issue? Do you have any recommendations on how to better handle memory management in Android / MVVMLight?

bstahlman commented 4 years ago

Did you solve this issue?

At the time we had thought so, but the root cause remains.

jamesmcroft commented 4 years ago

@bstahlman is this specifically to do with navigation causing the memory issues? It could be worth checking if you have dependencies registered which should be transient but aren't that are keeping a lot of data in memory when navigating between views.