-2

Possible Duplicate:
Find out memory leak?

Problem with finding leak in this code, so please help me. Thanks in advance. Regards

ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(ref, kABPersonPhoneProperty);
        for(CFIndex j = 0; j < ABMultiValueGetCount(phoneNumbers); j++)
        {
            CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phoneNumbers, j);
            NSString *phoneNumber = (NSString *) phoneNumberRef;


        contact.strMobileNo = phoneNumber;
        NSLog(@"phoneNO is %@", phoneNumber);
        CFRelease(phoneNumberRef);

        ABMultiValueRef emails = ABRecordCopyValue(ref, kABPersonEmailProperty);
        for(CFIndex k = 0; k < ABMultiValueGetCount(emails); k++)
        {
            CFStringRef emailRef = ABMultiValueCopyValueAtIndex(emails, k);
            NSString *mailid = (NSString *) emailRef;
            contact.strMail = mailid;
            NSLog(@"Email is %@", mailid);

            CFRelease(emailRef);

        }
        CFRelease(emails);

    }       
    CFRelease(phoneNumbers);
Community
  • 1
  • 1
Maidul
  • 1,289
  • 16
  • 30

1 Answers1

1

If you are using Instruments to detect leaks, take into account the fact the leaks will show you the point where the leaked memory is allocated, not the point where the leak actually happens.

Your code seems right to me. You correctly release objects you get through AB methods. On the other hand, you assign a couple of the to ivars of your contact object. It could be possible that the leak happens there, so have a look also to the lifecycle of contact, or to any object containing it.

sergio
  • 68,819
  • 11
  • 102
  • 123