我正在开发钛合金应用程序。我有多个XML文件。每个XML文件都有相同的视图,每个视图的ID和功能都是一样的。这种认识是正确的,或者我必须为所有对象分配不同的id和不同的命名函数以防止内存泄漏。我的意思是每个xml的代理在内存上相同或不同?了解合金结构
home.xml
<Alloy>
<Window id="home">
<View id="Container" onTouchend="fooFunction"> </View>
</Window>
</Alloy>
detail.xml
<Alloy>
<Window id="detail">
<View id="Container" onTouchend="fooFunction"> </View>
</Window>
</Alloy>
other.xml
<Alloy>
<Window id="other">
<View id="Container" onTouchend="fooFunction"> </View>
</Window>
</Alloy>
以及如何从清洗对象内存何时关闭窗口以防内存泄漏?
编辑用于防止内存泄漏的窗口关闭事件;
$.detail.addEventListener("close", function() {
// this listerner creates when window open for paused app event
Ti.App.removeEventListener("app:RefreshJson", fncRefreshJson);
$.Container.removeAllChildren();
$.detail.removeAllChildren();
$.removeListener();
$.destroy();
// listview creates on the fly when new window opens
// then I am adding it into $.Container
listView = null;
$.detail = null;
});
我用我的控制器代码编辑我的问题?你有什么建议?这是正确的做法吗? – Kerberos
你有内存泄漏的具体问题吗?您可能需要针对您遇到的问题发布问题。另请参阅[管理内存](http://docs.appcelerator.com/platform/latest/#!/guide/Managing_Memory_and_Finding_Leaks)。至于你的代码,'$ .destroy()'只在做[合金数据绑定]时需要(http://docs.appcelerator.com/platform/latest/#!/guide/Destroying_Data_Bindings)。是的,您确实需要删除全局事件侦听器。我会尽量避免它们,而是使用诸如主干事件之类的东西。 –
我打开10多个窗口。父窗口不关闭。你建议任何算法的多个Windows应用程序? – Kerberos