Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created August 31, 2012 18:27
Show Gist options
  • Save pec1985/3556938 to your computer and use it in GitHub Desktop.
Save pec1985/3556938 to your computer and use it in GitHub Desktop.
How to create a simple memory leak with Titanium
var memLeakArray = [];
function FirstWindow() {
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
var btn = Ti.UI.createButton({
title: 'open next',
width: Ti.UI.SIZE,
height: Ti.UI.SIZE
});
win.add(btn);
btn.addEventListener('click', function(){
SecondWindow().open();
});
return win
}
function SecondWindow() {
var win = Ti.UI.createWindow({
backgroundColor: '#ccc'
});
var btn = Ti.UI.createButton({
title: 'close',
width: Ti.UI.SIZE,
height: Ti.UI.SIZE
});
win.add(btn);
for(var i = 0; i < 20; i++) {
var l = Ti.UI.createLabel({
top:0,
text: 'meh'
});
// Memory Leak!!!
memLeakArray.push(l);
win.add(l);
}
btn.addEventListener('click', function(){
win.close();
});
return win;
}
FirstWindow().open();
@davidzhaohan
Copy link

Can't crash the app isn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment