Created
May 18, 2012 16:28
-
-
Save egomez99/2726237 to your computer and use it in GitHub Desktop.
commonJS GarbageCollector Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Run test 1 | |
var gced = require('create_gced'); | |
var win = gced.create_gced(); | |
win.open(); | |
/* | |
//When running by second time enable this: | |
setTimeout( | |
function(){ | |
gced = null; | |
win = null; | |
alert('released!'); | |
}, 15000); | |
*/ | |
//The negative case might work the same | |
//var non_gced = require('create_non_gced'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.create_gced = function() { | |
var $win = Ti.UI.createWindow({ | |
width : '100%', | |
height : '100%', | |
backgroundColor : '#d4d4d4', | |
title : 'GarbageCollected', | |
layout : 'vertical' | |
}); | |
var $btn = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn); | |
var $btn1 = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn1); | |
var $btn2 = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn2); | |
$win.addEventListener('close', function() { | |
$btn = null; | |
$btn1 = null; | |
$btn2 = null; | |
Ti.API.info('Close & releasing btns'); | |
}); | |
$win.addEventListener('click', function() { | |
this.close(); | |
}); | |
return $win; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.create_non_gced = function() { | |
var $win = Ti.UI.createWindow({ | |
width : '100%', | |
height : '100%', | |
backgroundColor : '#d4d4d4', | |
title : 'NON GarbageCollected', | |
layout : 'vertical' | |
}); | |
var $btn = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn); | |
var $btn1 = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn1); | |
var $btn2 = Ti.UI.createButton({ | |
left : 10, | |
right : 10, | |
height : 24 | |
}); | |
$win.add($btn2); | |
return $win; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment