0

I am getting low memory warning after updating some 20 contacts with images. I have placed the code. Can anyone tell what might be the reason?

    NSString *imagepath = [[IDLFactory documentsDirectoryPath] stringByAppendingFormat:@"/%@",value];

        NSData *dataRef = [[NSData alloc] initWithContentsOfFile:imagepath]; 
        CFDataRef cfdata = CFDataCreate(NULL, [dataRef bytes], [dataRef length]);
        [dataRef release];
        dataRef = nil;
        CFErrorRef error;
        ABPersonRemoveImageData(inContact, &error); // <-- clean any image first from ref

        BOOL ret = ABPersonSetImageData(inContact, cfdata, &error);
        if (ret) 
        {
            ret = ABAddressBookSave(inAddressBook, &error);
        } else 
        {
            NSLog(@"Could not write the image to the person");
        }
        CFRelease(cfdata);

Thanks in advance

Manjunath
  • 4,545
  • 2
  • 26
  • 31

1 Answers1

0

First, I think ABPersonRemoveImageData() sometimes is not necessary, because it will fill with new data.

Second, I guess the memory is occupied by autorelease objects. You need to free these autorelease objects by NSAutoreleasePool. If you run the whole things on the same run loop, generally iOS will release those autorelease objects at some time.

AechoLiu
  • 17,522
  • 9
  • 100
  • 118
  • - ABPersonRemoveImageData() will remove if there is any image present or else it will return the FALSE as a return value. It will not fill with new data. - I am not using any autorelease objects to use autoreleasePool here. Anyhow i am having autoreleasePool in the method from where I am calling this snippet. – Manjunath Nov 24 '10 at 04:35