Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

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

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-05-07T11:18:36.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sn/a
ComponentsAndroid
LabelsSupportTeam, core
ReporterEduardo Gomez
AssigneeNeeraj Gupta
Created2012-04-23T08:20:43.000+0000
Updated2017-03-24T18:11:22.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

Droid Razr 2.3.5

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 DDMS).

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 > DDMS_Droid_2.1.0_TestCase1_a.jpg TestCase 1 - Button set to null > DDMS_Droid_2.1.0_TestCase1_b.jpg TestCase 2 - Button not being set > DDMS_Droid_2.1.0_TestCase2_a.jpg TestCase 2 - Button set to null > DDMS_Droid_2.1.0_TestCase2_b.jpg

Wiki Link

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

Attachments

FileDateSize
DDMS_Droid_2.1.0_TestCase1_a.jpg2012-04-23T08:24:39.000+0000342975
DDMS_Droid_2.1.0_TestCase1_b.jpg2012-04-23T08:24:39.000+0000300615
DDMS_Droid_2.1.0_TestCase2_a.jpg2012-04-23T08:24:39.000+0000308246
DDMS_Droid_2.1.0_TestCase2_b.jpg2012-04-23T08:24:39.000+0000332120

Comments

  1. Opie Cyrus 2012-04-30

    This issue is invalid. The reason why is actually called out in the description: "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:" Key phrase here is: "as long as no other references to those child objects exist". A reference is anything that maintains a reference to the object (both the "button" variable and the view object keep their own references. Following that line of thought, setting view to null frees one of those references but there is still another ("var button").
  2. Eduardo Gomez 2012-05-02

    Address key notes in: TIDOC-608
  3. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source