[TIMOB-14103] iOS: Possible memory leak in add/removeRoute
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-10-22T22:33:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | 2013 Sprint 22, 2013 Sprint 22 API, Release 3.2.0 |
Components | iOS |
Labels | ios, leak, mapView, memory, routes |
Reporter | Carter Lathrop |
Assignee | Vishal Duggal |
Created | 2013-05-24T06:16:01.000+0000 |
Updated | 2013-10-24T00:11:52.000+0000 |
Description
*Problem*
From what I can see removeRoute() does not properly release the memory created. I have taken a deep dive into how it handles the MKPolyline and MKPolylineView objects that are created - one of each per call to addRoute() in a mapView. As soon as the route is deleted the MKPolyline object is released, but the MKPolylineView object is not. (I used Instruments for this check).
*Test Case*
var ppt = 1; // Change here if you want to try adding multiple routes per button press
var win = Ti.UI.createWindow();
var addButton = Ti.UI.createButton({title: "Add " + ppt, left:0, top: 0});
addButton.addEventListener("click", AddRoutes);
var deleteButton = Ti.UI.createButton({title: "Delete all", right: 0, top: 0});
deleteButton.addEventListener("click", DeleteRoutes);
var map = Ti.Map.createView({
top: 50
});
win.add(map);
win.open();
win.add(addButton);
win.add(deleteButton);
var routes = [];
var id = 0;
function AddRoutes() {
for(var i=0;i<ppt;i++) {
var r = {
name: (id++).toString(),
points: [
{latitude: 42.3353, longitude: -71.1705 },
{latitude: 42.3383, longitude: -71.1690 },
{latitude: 42.3358, longitude: -71.1670 },
{latitude: 42.3353, longitude: -71.1705 }
],
color: 'red',
width: 4
};
map.addRoute(r);
routes.push(r);
r = null;
}
// console.log(routes.length);
}
function DeleteRoutes() {
while(routes.length > 0)
map.removeRoute(routes.pop());
}
*Actual Results*
When analyzing the objects in memory in instruments it is clear that each and everyone of the MKPolyline objects are released, but not a single one of the MKPolylineView objects.
*Expected Results*
Both MKPolyline objects and MKPolylineView objects are released.
Is there is leak here, or have I completely missunderstood how the release of these objects should work?
I can confirm this. My app needs to draw many routes on the map, we are struggling with the memory issue now.
Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/4822
Closing ticket as fixed. Verified both MKPolyline and MKPolylineView objects are released while using Instruments. Tested on: Titanium Studio, build: 3.2.0.201310230548 OS: Mac OS X Mountain Lion (10.8.5) SDK build: 3.2.0.v20131023140842 Ti CLI: 3.2.0 (72f7426b4ee6c2d2883c666d5b7e03906a16012f) Xcode: 5.0.1 Devices: iphone 5 (6.1.3), iphone 5c (7.0.1)