0

I have big problem with getting images from AddressBook, below I paste my code. This imageData never has been deallocated, on my Allocations Instruments it looks that it`s always in memory it never release.

@autoreleasepool {
            CFDataRef imageData = ABPersonCopyImageData(record);
            if(imageData)
            {
                CFRetain(imageData);
                CFRelease(imageData);
                imageData = NULL;
                imageData = nil;
            }
        }

2 Answers2

2

You are over-retaining imageData

CFDataRef imageData = ABPersonCopyImageData(record); // Returns a +1 owned object
if(imageData)
{
    CFRetain(imageData);     // This is now +2
    CFRelease(imageData);    // This is now +1
    imageData = NULL;        // You've lost the pointer that lets you release it
    imageData = nil;         // Does nothing.
}

Having this in an autoreleasepool does nothing as you don't have any autoreleased objects.

Have a look at the Core Foundation Create Rule

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • It nothings change, same situation. CFDataRef imageData = ABPersonCopyImageData(record); // Returns a +1 owned object if(imageData) { CFRelease(imageData); } – user2429398 Jun 19 '13 at 19:48
  • I was commenting your code to show you what you were doing wrong. You need to remove the CFRetain call – Abizern Jun 20 '13 at 04:52
0

You need to CFRelease(imageData ) when you are done with it. Its a Core Foundation object - the autorrelease pool does you no good.

David H
  • 40,852
  • 12
  • 92
  • 138
  • I use it only once in this moment "CFDataRef imageData = ABPersonCopyImageData(record);", I don`t use it anymore. I want get cfdataref and release it immediately. – user2429398 Jun 19 '13 at 18:50
  • You don't make any sense. So you release it now, and the problem is gone? Then just say that - and either mark this as the correct answer, or answer your own question then select it with what you did. Ah, you changed the code since I answered - fine select @Abizern's answer. – David H Jun 20 '13 at 21:34