Using Appcelerator doesn’t mean you don’t have to take care of memory leaks. Odds are there is at least one leak in your app right now. Relatively unknown is that this can be easily detected with some XCode Instruments. I’ll show you how.
Walkthrough
Run your app from Titanium Studio or CLI in the Simulator or on a device. Then launch XCode and go to Xcode > Open Developer Tool > Instruments
Now choose Allocations
In the drop down menu go to Attach to Process and select your app in the System section if it runs in Simulator or on the device listed. The list is not alphabetically sorted so keep looking :)
Filtering
Filter on TiUI or Proxy and you will see the Titanium objects appearing while navigating through your app. The objects should be disappearing when they are no longer active. Each label will appear as a TiUILabel so you won’t know which label. Try to debug one window at a time so you get a better idea where the leak is exactly.
Gotcha
Be aware of the fact that when you are running in the Simulator the amount of memory is equal to your Mac. Garbage collection might take a while because of that. Unfortunately there is no way to manually trigger the garbage collector. A workaround is hooking the Allocation instrument up to a device with little memory.
Also see this talk on leaking apps at Codestrong 2012:
Comments
Daniula
Regarding gotcha and triggering garbage collector on simulator: what about option: “Simulate Memory Warning” with nice SHIFT+CMD+M shortcut? I got impression it helps in forcing GC.
Fokke Zandbergen
Really? Nice!
Wienke Giezeman Post author
Nice one!
John Dalsgaard
Great article – thanks!
It didn’t work for me the first times I tried it. And after some trial-and-error (and a couple of other tutorials) I found that once I had attached to the process I needed to press the “record” button. It may be obvious to many – but should new readers not know then they should be able to get it working quicker ;-)
/John
TV Food Maps (@tvfoodmaps)
I’m trying this with an alloy app on 3.5.1 and xcode 6.2. If I do it this way the app crashes as soon as I hit record. If I do it via the xcodeproj file the app doesn’t crash but I get no TiUI* instances. Has anyone tried this on these builds?
Codex Labs (@CodexLabs)
I’m seeing the same issue. It’s not just alloy, it’s titanium period. I strongly suspect it is either Xcode 6.2 or something Titanium did after 3.5.0. This is a high priority for me to see fixed.
codexlabs
We finally released a free codexcasts episode on how to solve this issue: https://codexcasts.com/episodes/titanium-and-xcode-instruments-6-3