Monthly Archives: January 2013

Using code generated flags to debug with Instruments

I discovered a great debugging tool today from the article Flags: very useful when debugging with Instruments   The article talks about how to put up flags from your code that appear in the Instruments window.    This is a feature that is new to Instruments 4.0 and is described in the Apple docs at New Features in Instruments 4.0   Let’s jump to the end and show you an example of what you can put up in your Instruments display:


Note the yellow flags above the trace.   These were generated in my code within a loop.    If you click on a flag you can see the text that I generated for the flag “Loop index 38” along with the source file, line number of the code generating the flag and the method  being executed.

Continue reading

Using @autoreleasepool to reduce your memory footprint

When I was reviewing iOS memory management in the Apple documentation, I came across the section Use Local Autorelease Pool Blocks to Reduce Peak Memory Footprint

With the introduction of ARC (Automatic Reference Counting) memory management is largely taken care of for you.   There are still some cases you need to worry about though, including an increase in your memory footprint caused by creating temporary objects in a loop.

Consider the following code that allows me to populate some test data into the iOS Address Book.   Note that I inserted a sleep(4) after each iteration to more clearly show the memory allocation picture in steady state before a new iteration begins.

Continue reading

Core Data issues with memory allocation

I’m using Core Data in an application that I am developing that uses the Address Book.   I created some test data and started writing some code that imported this information into Core Data.    Curious about the memory usage of this import, I used the Allocations Instrument for analysis and thus began a long process where I believe I may have uncovered several bugs related to Core Data memory management.

What prompted the analysis?

I have seen references indicating that your app risks being shut down for memory usage when you use more than 20 MB of RAM.   A couple interesting articles include:

Continue reading