Tag Archives: memory

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

Memory management with iOS

In creating my first iPhone app which uses the Address Book, I discovered the world of memory management with iOS.  I wanted to share a few things I’ve learned and provide lots of links for your reference.

ARC, retain counts and CFRelease

Admittedly, if you stick strictly to Foundation code, you probably don’t need to be concerned too much about what happens under the hood.   With the introduction of ARC (Automatic Reference Counting), iOS takes care of much of this for you.  It’s when you also need to deal with Core Foundation (CF), which the Address Book uses, that things become tricky.   CF has a concept of object ownership and memory management using retain counts.   An object can have multiple owners (retain count > 1), but when you are done with that object the retain count had better be zero or you’ll create memory leaks.    To accomplish this, you need to use CFRelease().

Continue reading