Languages Magazine

How to Find iOS App Memory Leaks

By Expectlabs @ExpectLabs

Learn how to locate memory leaks in your iOS apps with the help of Expect Labs’ Software Engineer, Juan Rodriguez.

TRANSCRIPT:

Hello, my name is Juan Rodriguez, and I am a software engineer for Expect Labs. Today we’re going to talk to about a set of tools that be used when testing and developing iOS applications. One of the main challenges of iOS development is tracking down and finding memory leaks. Sometimes memory leaks can be easy to find. Sometimes you can just run the analyzer and it will tell you which line of code can be causing a memory problem. But other times, memory leaks can be hidden deep inside the logic of the application and those are the ones that are hard to find.

However, we have this set of tools that’s called the Xcode instruments that can be used to highly simplify this task of finding memory problems. You open up these instruments by clicking Command + I while you’re in Xcode and it will open up a dialog that contains a set of tools with really different purposes that you can use. The one that I want to talk about today, it’s call the applications tool. If you run your app against these two, there are two things that are really useful that you can do for finding memory problems. The first one, you will notice that there is a graph of the heap that the application is using. What I like to do there, is on my device, I go to the start page of my application, and I make a memory snapshot. Then I navigate to my application. I go to a different views, a different views controllers and I come back to the start page. Then I make another snapshot. So the allocation tool is going to take these two snapshots and it’s going tell you what is the difference between them. In particular, it’s going to tell you which objects were created in the process, but were not destroyed in the process. And then, of course, it’s up to you, the programmer, to find out whether those objects should be leaving or not, If they shouldn’t be leaving then it’s probably a memory leak.

The second thing that you can do, is you can actually cut down individual objects in the execution time. So using this tool, you can search for any particular object. You can click on it, and it’s going to give you detailed information about the retain count for that object. It’s going to tell you the history; whenever the retain count either increased or decreased, and exactly which line of code and what function were making those retain increase or decreases. Then of course it’s up to you to decide whether that should be happening or not. I like to run my applications through these instruments as often as possible. Especially after making big changes in the code, because that’s when memory leaks tend to appear. I hope this was useful to you.



Back to Featured Articles on Logo Paperblog

Paperblog Hot Topics

Magazines