Bug 39489 - [Android] Memory leak when using NavigationPage with Maps
Summary: [Android] Memory leak when using NavigationPage with Maps
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.1.0
Hardware: All Mac OS
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-09 18:18 UTC by Paul DiPietro [MSFT]
Modified: 2016-11-30 16:26 UTC (History)
7 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
Reproduction project (51.28 KB, application/zip)
2016-03-09 18:20 UTC, Paul DiPietro [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Paul DiPietro [MSFT] 2016-03-09 18:18:04 UTC
When using a NavigationPage with a ContentPage that contains a map on Android and a button to navigate to a new page (of the same layout), navigating back and forth repeatedly will eventually cause an out of memory error.

## Reproduction steps
- Update API key as necessary for Google Play Services
- Run application
- Use the button to navigate forward to a new page, and navigate back as desired
- An out of memory error should eventually occur (testing an S5, it took maybe 25-30 pages or so).
Comment 1 Paul DiPietro [MSFT] 2016-03-09 18:20:08 UTC
Created attachment 15333 [details]
Reproduction project
Comment 3 cjameson 2016-05-13 09:47:56 UTC
I have managed to fix the memory leak. I have subclassed the xamarin map renderer and in the Dispose method, instead of calling base.Dispose() I am calling the below (as well as the code in the current MapRenderer.Dispose method)

(this.Control as MapView).OnPause();
(this.Control as MapView).OnDestroy();
(this.Control as MapView).Dispose();

The issue is Xamarin aren't calling these in the dispose, so the view lives on in memory and causes memory leaks. So to fix, these need to be applied in the Dispose method of the MapRenderer at somne point
Comment 4 Guilherme 2016-09-02 11:31:10 UTC
Do you mind sharing a sample project ? ty
Comment 5 Rui Marinho 2016-09-27 10:52:58 UTC
Should be fixed in 2.3.4-pre1
Comment 6 Parmendra Kumar 2016-11-30 16:26:30 UTC
I have checked this issue with Xamarin.Forms 2.3.4-pre1 and I am not getting any crash.

Hence closing this issue.