Problem
Memory leak when removing MapView (Map Module v2)
Titanium SDK 3.2.0 (HEAD)
Android 4.2.1
Nexus S
Test case
Run the app below.
Dump HPROF file
Tap on "Toggle" multiple times.
Dump HPROF file
Compare memory usage of second memory dump against first one: TiUIFragement$1 and TiUIMapView do not get released, when the MapView is removed from the screen and with this the whole Google Map View is leaked (which is quite a lot of memory.)
var win = Ti.UI.createWindow({
modal: false,
backgroundColor: 'white'
});
var button = Ti.UI.createButton({
top: '10dp',
width: '100dp',
height: '40dp',
title: 'Toggle',
});
var MapModule = require('ti.map');
var map = MapModule.createView({
top: '60dp',
mapType:MapModule.NORMAL_TYPE
});
var showingMap = true;
button.addEventListener('click', function(evt) {
if (showingMap) {
this.window.remove(this.map);
} else {
this.window.add(this.map);
}
showingMap = !showingMap;
});
win.add(button);
win.add(map);
win.open();
I could resolve this memory leak by adding the following to TiUIFragment:
And adding a call to "super.release()" at the end of "release()" in TiUIMapView.
Hi [~philet], Thanks for bring it up to our attention. Can you please provide either device or console output logs? Make sure to fill out reports according [Jira checklist](http://docs.appcelerator.com/titanium/latest/#!/guide/How_to_Submit_a_Bug_Report-section-29004732_HowtoSubmitaBugReport-JIRATicketChecklist) so we are able to diagnose issues quicker. Also, would be great if you can share HPROF summary or screenshots to have a wider insight around this. Thanks.
Hi Eduardo I have attached the log, 2 HPROF files as well as 2 screenshots containing the comparison of the 2 HPROF files. Thanks for looking into this. Regards, Philippe
Master PR: https://github.com/appcelerator/titanium_mobile/pull/4718 + https://github.com/appcelerator-modules/ti.map/pull/12
Verified the fix by running the sample code & grabbing the hprof dumps before and after toggling the maps. Did not find any leaks. Closing. Environment: Appcel Studio : 3.2.0.201312181652 Ti SDK : 3.2.0.v20131218153242 Mac OSX : 10.8.5 Alloy : 1.3.0-cr2 CLI - 3.2.0-cr3 Samsung Galaxy S4 running android 4.2.2