Bug 39489 - [Android] Memory leak when using NavigationPage with Maps
Summary: [Android] Memory leak when using NavigationPage with Maps
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
Depends on:
Reported: 2016-03-09 18:18 UTC by Paul DiPietro [MSFT]
Modified: 2016-11-30 16:26 UTC (History)
7 users (show)

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

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

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.

Note You need to log in before you can comment on or make changes to this bug.