Memory Leak
http://docs.appcelerator.com/platform/latest/#!/guide/Managing_Memory_and_Finding_Leaks
教學
- http://www.tidev.io/2014/03/27/memory-management/
- http://blog.sina.com.cn/s/blog_62f189570101cows.html
如何檢查
http://www.lis186.com/posts/7640
原則
- Don’t use global variables. If you think you need global variables, think again. Always use ‘var’ when declaring variables (they’re globals if you don’t).
- Don’t create references to objects (use anonymous object instantiated inline). If you do create references, null them out when you’re done with them.
- Encapsulate view creation in commonJS modules, which can be instantiated and then deallocated later. (Alloy helps with this because it is commonJS by default and a lot of older hand-rolled Classic code was not).
- Destroy collections ($.destroy()) when using view/model binding & you’re done with the associated view
- Don’t use, and watch out for implicitly-created closures unless you know what you’re doing and later deallocate those objects.
- Set global event listeners (Ti.App.addEventListener, Ti.Geolocation.addEventListener, etc.) with care – in your top-level controller, remove as soon as you can, never more than once, etc.
- Learn JavaScript. It’s not Java, C#, Ruby, etc. It works the way it works so be all zen-like and accept it. Learn about scoping, hoisting, prototypal inheritance, closures, etc. Yeah, it’s a lot to learn. But you’re a developer, you can do it.
Alloy
- http://www.jamesdraper.info/blog/titanium-alloy-memory-tips