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

iOS: Memory Leak: Objects created in a Ti.UI.tabGroup are not released when the tabGroup is closed

    Details

    • Story Points:
      1

      Description

      Problem

      Objects created in a Ti.UI.tabGroup are not released when the tabGroup is closed.

      Reproducible steps:

      1. Run the code below.
      2. Use the instruments application to monitor the memory
      3. Click on Open tabgroup button
      4. Click on close button

      Please see TiUITabproxy on the category. It is never released from the memory.

      Expected behavior:

      Customer wants to release the memory of a tab.

      Tested with the next specs:

      Simulator

      iPhone 4
      Version of the device: 5.0.1

      Titanium Studio, build: 1.0.8.201112291658
      Titanium SDK: 1.8.0.1

      More info:

      Please see the video attached.

      Code:

      function createTabGroup() 
      {
      	var colors = ['#ff9966', '#99ff66', '#6699ff', '#66ffff', '#ffff66'];
       
      	function openWindowOnStack(i) 
      	{
      		var win = Ti.UI.createWindow(
      		{
      			title : 'Window ' + i,
      			backgroundColor : colors[i]
      		});
      		
      		win.addEventListener('open', function(evt) 
      		{
      			Ti.API.info('Opened: ' + evt.source.title);
      			if(i < 4) 
      			{
      				setTimeout(function() 
      				{
      					openWindowOnStack(i + 1);
      				}, 500);
      			}
      		});
      		
      		win.addEventListener('close', function(evt) 
      		{
      			Ti.API.info('Closed: ' + evt.source.title);
      			trackClosedWindow(tab1, evt.source);
      		});
      		
      		openInTab(tab1, win);
      	}
       
      	var navButton = Ti.UI.createButton(
      	{
      		title : 'Open Windows'
      	});
       
      	var outer = Ti.UI.createWindow(
      	{
      		title : 'Root Window',
      		backgroundColor : '#d0d0d0',
      		rightNavButton : navButton
      	});
       
      	outer.rightNavButton.addEventListener('click', function() 
      	{
      		openWindowOnStack(0);
      	});
      	
      	function trackClosedWindow(thistab, window) 
      	{
      		var windows = thistab.windows || [];
      		
      		for(var w = windows.length - 1; w >= 0; w--) 
      		{
      			if(windows[w] == window) 
      			{
      				windows[w] = null;
      				windows.splice(w, 1);
      				break;
      			}
      		}
      		
      		thistab.windows = windows;
      	}
       
      	function closeAllInTab(thistab) 
      	{
      		var windows = thistab.windows || [];
      		
      		for(var w = 0; w < windows.length; w++) 
      		{
      			windows[w].close();
      			windows[w] = null;
      		}
      		
      		thistab.windows = windows = [];
      	}
       
      	function openInTab(thistab, window) 
      	{
      		var windows = thistab.windows || [];
      		windows.push(window);
      		thistab.open(window);
      		thistab.windows = windows;
      	}
       
      	var tabGroup = Ti.UI.createTabGroup();
      	
      	var tab1 = Ti.UI.createTab(
      	{
      		window : outer,
      		title : 'Touch Me'
      	});
      	
      	tabGroup.addTab(tab1);
       
      	var button2 = Ti.UI.createButton(
      	{
      		title : 'close',
      		height : 35,
      		width : 200
      	});
      	
      	outer.add(button2);
      	
      	button2.addEventListener('click', function(e) 
      	{
       
      		outer.remove(button2);
      		outer.rightNavButton = null;
      		button2 = null;
      		navButton = null;
       
      		closeAllInTab(tab1);
      		tabGroup.removeTab(tab1);
      		tab1.window = null;
      		tab1 = null;
       
      		tabGroup.tabs = null;
      		tabGroup.close();
      		tabGroup = null;
       
      		outer.close();
      		outer = null;
       
      		Ti.API.info('Closed tab group');
      	});
      	
      	return tabGroup;
       
      }
       
      var win1 = Ti.UI.createWindow(
      {
      	backgroundColor : '#fff',
      	title : "Home"
      });
       
      var button1 = Ti.UI.createButton(
      {
      	title : 'Open tabgroup',
      	height : 35,
      	width : 200
      });
       
      button1.addEventListener('click', function(e) 
      {
      	var tabGroup1 = createTabGroup();
      	tabGroup1.open();
      	Ti.API.info('Opened tab group');
      });
       
      win1.add(button1);
       
      win1.open();
      
      

      Helpdesk

      APP-443889

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mstepanov Max Stepanov
                Reporter:
                framirez Francisco Antonio Duran Ramirez
              • Watchers:
                7 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:

                  Git Source Code