Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-14103

iOS: Possible memory leak in add/removeRoute

    Details

      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?

        Attachments

          Activity

            People

            • Assignee:
              vduggal Vishal Duggal (Inactive)
              Reporter:
              clathrop Carter Lathrop
              Reviewer:
              Pedro Enrique (Inactive)
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-16649
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code