我正在解决iOS应用程序Ti SDK 6.2中的内存泄漏问题,但没有取得多大成功。
打开和关闭窗口时,xcode Instruments分配工具会显示许多TiUIxxxxProxy对象仍保留在内存中。
您可以在附加的xcode Instruments分配图像中看到,在关闭window2后,代理对象仍然存在(窗口、表等)。更糟糕的是,多次打开和关闭window2会不断添加使用内存的其他代理对象。
应用程序。js公司
require('Window1').CreateWindow().open();
Window1.js
exports.CreateWindow = function(){
try{
var window1 = Ti.UI.createWindow({
title:'Window 1',backgroundColor:'yellow',
});
var button1 = Ti.UI.createButton({
top:'50dp', center:'50%',
borderWidth:'1dp',borderColor:'black',
title:' Open Window 2 '
});
window1.add(button1);
button1.addEventListener('click', function() {
var win2 = require('Window2').CreateWindow();
win2.open();
});
return window1;
}
catch(e){
alert('Window 1 Error: ' + e);
}
};
Window2.js
exports.CreateWindow = function(){
try{
var window2 = Ti.UI.createWindow({
title:'Window 2',layout:'vertical'
,top:'200dp',bottom:'200dp',width:'80%'
,backgroundColor:'orange'
});
var button2 = Ti.UI.createButton({
top:'50dp', center:'50%',
borderWidth:'1dp',borderColor:'black',
title:' Close Window 2 '
});
window2.add(button2);
button2.addEventListener('click', function() {
window2.close();
});
var tvRow1 = Ti.UI.createTableViewRow({ });
var labelRow1 = Ti.UI.createLabel({
color:'#000000',
left:'15dp',
top:'10dp',
text:'Label in row 1'
});
tvRow1.add(labelRow1);
var tableViewSection1 = Ti.UI.createTableViewSection({ });
tableViewSection1.add(tvRow1);
var arrayTableSections = [];
arrayTableSections.push(tableViewSection1);
var table2 = Titanium.UI.createTableView({
data: arrayTableSections,
top:'50dp',
left:'50dp',
right:'50dp',
height:Ti.UI.SIZE,
backgroundColor:'#ffffff' ,
borderColor:'black',borderWidth:'1dp'
});
window2.add(table2);
return window2;
}
catch(e){
alert('Window 2 Error: ' + e);
}
};