IOS, Tools

Debug memory leaks with XCode Instruments

Debug memory leaks with XCode Instruments

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.

mycodetips

Passionate about coding and software development holding 10+ Years of experience including 6+ years of experience on Mobile application Development.

More Posts