优化 Titanium 应用程序的最佳方法有哪些? [英] What are some of the best ways to optimize a Titanium app?

查看:22
本文介绍了优化 Titanium 应用程序的最佳方法有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于钛的 iOS 应用程序,它基本上遵循我自己的 MVC 结构.它有大约 30 个视图和大量网络连接来进行 API 调用.因此,该应用程序似乎在除 iPhone4S 之外的实际设备上运行缓慢.具体来说,从多任务菜单重新启动应用程序后,它会挂起大约 10 秒.有什么提示吗?

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?

推荐答案

您主要需要关心内存泄漏.您有一个关于这个主题的非常重要的网络广播.简而言之;非常小心:

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

  • 避免大的全局对象:它们有对世界的引用,所以这些引用不会被清除
  • 消除任何循环依赖:垃圾收集器不是垃圾收集器!当有 0 个引用时,它只计算引用并杀死对象.对于圆形对象,总是有 1 个引用.
  • 避免在 Ti.App 上发生事件:糟糕!但是请求 addEventListener 的对象永远在 Ti.App 侦听器总线中.总线保留一个引用以将事件发送到该对象,因此它将永远存在,其引用也将永远存在.
  • 注意其他事件.
  • 也要注意动画:它们具有引用应用程序的回调.这些回调函数(即变量)可能会保留在内存中,其引用也是如此.
  • 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.

简而言之,您的应用程序必须尽可能接近没有后向引用的简单树.当你在树中上升时写 myDownObject=null .在 Mac 上大量使用 Instruments,带有代理"过滤器.所有钛对象都是 UIProxy.

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.

这篇关于优化 Titanium 应用程序的最佳方法有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆