Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8857] iOS: Destroying a parent object (setting it to null) it won't destroy any child objects

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-04-27T16:28:13.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sn/a
ComponentsiOS
LabelsSupportTeam, core
ReporterEduardo Gomez
AssigneeStephen Tramer
Created2012-04-23T08:08:06.000+0000
Updated2012-04-30T09:34:35.000+0000

Description

Issue

"Destroying a parent object (setting it to null) will destroy any child objects as long as no other references to those child objects exist. Consider the following code snippet to get a feel for the specifics:"

Tested on

iOS 5 simulator

Test Case 1

var win = Titanium.UI.createWindow({
	title: 'Main',
	exitOnClose: true,
	fullscreen: false,
	navBarHidden: false,
	backgroundColor: 'gray'
});

var button = Ti.UI.createButton({
    // parameters go here...
    title: 'deletes the view and its proxy,\nbut not the button!',
    backgroundColor: 'red'
});
var view = Ti.UI.createView({
    // some parameters here...
   borderRadius:10,
   top: 15
});
view.add(button);
win.add(view); 
win.addEventListener('click', function(){
	// ... later
	win.remove(view);  // view & button still exist
	view = null; //deletes the view and its proxy, but not the button!
});

win.open();

So Having button set to null do get released (as seen in Instruments).

Test Case 2

var win = Titanium.UI.createWindow({
	title: 'Main',
	exitOnClose: true,
	fullscreen: false,
	navBarHidden: false,
	backgroundColor: 'gray'
});

var button = Ti.UI.createButton({
    // parameters go here...
    title: 'deletes the view and its proxy,\nbut not the button!',
    backgroundColor: 'red'
});
var view = Ti.UI.createView({
    // some parameters here...
   borderRadius:10,
   top: 15
});
view.add(button);
win.add(view); 
win.addEventListener('click', function(){
	// ... later
	win.remove(view);  // view & button still exist
	view = null; // deletes the view and its proxy, but not the button!
	button = null;//do get released
});

win.open();

Additional info

Test results and its corresponding screenshots: TestCase 1 - Button not being set > InstrumentsProxies_2.1.0_TestCase1_a.jpg TestCase 1 - Button set to null > InstrumentsProxies_2.1.0_TestCase1_b.jpg TestCase 2 - Button not being set > InstrumentsProxies_2.1.0_TestCase2_a.jpg TestCase 2 - Button set to null > InstrumentsProxies_2.1.0_TestCase2_b.jpg

Wiki Link

https://wiki.appcelerator.org/display/guides/Managing+Memory+and+Finding+Leaks#ManagingMemoryandFindingLeaks-WhenTitaniumreleasesmemory

Attachments

FileDateSize
InstrumentsProxies_2.1.0_TestCase1_a.jpg2012-04-23T08:13:32.000+0000107170
InstrumentsProxies_2.1.0_TestCase1_b.jpg2012-04-23T08:13:32.000+000097060
InstrumentsProxies_2.1.0_TestCase2_a.jpg2012-04-23T08:13:32.000+0000109796
InstrumentsProxies_2.1.0_TestCase2_b.jpg2012-04-23T08:13:32.000+0000107590

Comments

  1. Stephen Tramer 2012-04-27

    Test case 1. is invalid. The button should still exist because there is still a reference to it; var button.
  2. Stephen Tramer 2012-04-27

    Test case is invalid. The button is managed correctly because it still has a reference.
  3. Eduardo Gomez 2012-04-27

    @Stephen Does that mean nulling that proxy should be done explicitly? i.e. button = null;
  4. Stephen Tramer 2012-04-27

    Yes. Please do not reopen tickets to ask a question.
  5. Stephen Tramer 2012-04-30

    Closing issue; requires no further validation. Please see Opie's description on the companion Android ticket for any more specific details.

JSON Source