Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14772] Android: Memory leak when removing MapView (Google Maps module v2)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-09-20T20:48:25.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 19, 2013 Sprint 19 API, Release 3.2.0
ComponentsAndroid
Labelsn/a
ReporterPhilippe Wueger
AssigneeHieu Pham
Created2013-08-05T14:27:31.000+0000
Updated2013-12-19T21:01:21.000+0000

Description

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();

Attachments

FileDateSize
after-5-toggles.hprof.zip2013-08-06T06:39:09.000+00002856601
before-baseline.hprof.zip2013-08-06T06:39:09.000+00002146222
log.txt2013-08-06T06:39:09.000+000018412
Screen Shot 2013-08-06 at 08.30.03.png2013-08-06T06:39:09.000+000021311
Screen Shot 2013-08-06 at 08.30.23.png2013-08-06T06:39:09.000+0000105624

Comments

  1. Philippe Wueger 2013-08-05

    I could resolve this memory leak by adding the following to TiUIFragment:
       @Override
       public void release()
       {
         FragmentTransaction transaction = manager.beginTransaction();
         transaction.remove(fragment);
         transaction.commit();
         super.release();
       }
       
    And adding a call to "super.release()" at the end of "release()" in TiUIMapView.
  2. Eduardo Gomez 2013-08-05

    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.
  3. Philippe Wueger 2013-08-06

    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
  4. Eduardo Gomez 2013-08-06

  5. Hieu Pham 2013-09-19

    Master PR: https://github.com/appcelerator/titanium_mobile/pull/4718 + https://github.com/appcelerator-modules/ti.map/pull/12
  6. Lokesh Choudhary 2013-12-19

    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

JSON Source