How to find out about the contents of autoreleasepools on iOS?

563 views Asked by At

I'm looking to decrease the memory usage of my app, and one place we might be wasting memory is in our use of autoreleasepools. I think we have them everywhere appropriate right now, but I'm not certain, so I'd like to do some measurement at strategic points and see if more @autoreleasepool blocks would be useful.

I've done some research and found out about the following methods of investigating autoreleasepools, which may have worked in the past but apparently do not any more, at least in XCode 5:

  • +[NSAutoreleasePool showPools] - this is meant to print information about the active autoreleasepools, but doesn't seem to do anything any more - XCode doesn't think it's a thing

  • _objc_autoreleasePoolPrint - I've found a few references to this function on stack overflow, but XCode insists that it doesn't exist, and won't link against it if I declare it as extern

Our codebase is big enough that just sticking extra autoreleasepools everywhere would be a fools errand, so what I'm looking for is a way to find out how many objects are "in the pool" at any particular time. That way I can add more pools to the few places that need them, rather than throwing them everywhere.

If I have to be in Instruments or the debugger to find that out, that's not a problem - this is just something we'd use for testing, and wouldn't go out in a release.

Thanks for your help!

1

There are 1 answers

0
jace On

The use of Instruments would be a good idea in this case as it would offer a lot of extra information that can help you understand better the memory usage of your app. As a general introduction, I would recommend the session Fixing Memory Issues of the 2013 WWDC

Also, here is a link to an answer with some good extra tips

If you really want to examine the memory usage in some specific code segment, you could add some NSLog() to print timestamps in the Console and use them to find intervals in the graph, but I find it is always better to just look the data as a whole and try to achieve a memory graph as uniform as possible and autorelease pools can help in this by spreading the usage more evenly.