What are some of the best ways to optimize a Titanium app?

时光毁灭记忆、已成空白 提交于 2020-01-21 08:40:26

问题


I have a titanium based iOS app that basically is following my own MVC structure. It has around 30 views and a lot of network connections to do API calls. So, it seems that the application is performing assumably sluggish on an actual device except iPhone4S. Specifically, the app would hang for about 10s after re-launching it from the multi-tasking menu. Any tips?


回答1:


You mostly have to care about memory leaks. You have a VERY important webcast on the subject. In short; be very careful to :

  • avoid big global objects : they have references to the world, so these references won't be cleared
  • eliminate any circular dependances : the garbage collector is NOT a garbage collector ! It just count references and kill objects when there is 0 refs. With circular objects, there is always 1 ref.
  • Avoid events on Ti.App : ouch that sucks ! But the object that ask addEventListener is for ever in the Ti.App listener bus. The bus keeps a reference to send the event to that object, so it will be there forever, so will be its references.
  • Be careful with other events.
  • Be also careful with animations : they have callbacks that have references to the application. These callbacks are function (so variables) that may stay in memory, so do its references.

In short, your application must be as close as possible to a simple tree with no backward reference. Write myDownObject=null when you go up in the tree. Use HEAVILY Instruments on your mac, with a 'Proxy' filter. All titanium objects are UIProxy.



来源:https://stackoverflow.com/questions/9115811/what-are-some-of-the-best-ways-to-optimize-a-titanium-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!