问题
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