Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to track memory management while testing my iPhone App?

While developing my app I have come to realize that the majority of my app crashes have arisen from poor memory management.

I understand I can print or log retain counts through NSLog (@"retain count is:%d",[myInstance retainCount]);

But isn't there a better, less manual method? Possibly a visual representation of your objects and instances?

answered. Cheers, Adam & Jason. :-)

like image 815
Dan Morgan Avatar asked Jan 06 '09 11:01

Dan Morgan


People also ask

How is memory management handled on iOS?

Memory management in iOS was initially non-ARC (Automatic Reference Counting), where we have to retain and release the objects. Now, it supports ARC and we don't have to retain and release the objects. Xcode takes care of the job automatically in compile time.

How much memory is too much for iOS app?

16GB of RAM is the highest amount of RAM ever offered in an iPhone or iPad, and the 5GB limitation means that apps aren't able to utilize even half of what the iPad Pro has to offer.

What is memory leak in iOS?

As per Apple, a memory leak is: Memory that was allocated at some point, but was never released and is no longer referenced by your app. Since there are no references to it, there's now no way to release it and the memory can't be used again.


Video Answer


3 Answers

Use the Leaks and Object Allocation tools through XCode.

Run > Start with Performance Tool > ...
like image 107
adam Avatar answered Nov 14 '22 22:11

adam


In addition to the other answers, I would highly recommend using clang to do a static memory analysis of your code. It won't catch every memory-management error, but it does catch quite a lot. If your chief problem seems to come from memory management errors, clang will go a long way toward finding those errors. Clang is free, at http://clang.llvm.org/

like image 24
Tom Harrington Avatar answered Nov 14 '22 23:11

Tom Harrington


As Adam suggests, Instruments is a very useful tool for these kinds of things. It's fairly easy to use, but can be a bit overwhelming at first. I suggest perusing the Instruments User Guide as you get started. It's pretty easy to follow and is helpful until you've used Instruments for a while. Even without reading the guide, however, Instruments is still far easier and more intuitive than littering your code with NSLog() calls and trying to parse the output yourself ;)

like image 25
Jason Coco Avatar answered Nov 14 '22 21:11

Jason Coco