Skip to content

Instantly share code, notes, and snippets.

@egomez99
Created May 18, 2012 16:28
Show Gist options
  • Save egomez99/2726237 to your computer and use it in GitHub Desktop.
Save egomez99/2726237 to your computer and use it in GitHub Desktop.
commonJS GarbageCollector Sample
//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');
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;
}
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