这段代码有什么问题,我在这段代码中漏了什么?

时间:2011-07-13 07:27:40

标签: ios ios4

  

可能重复:
  Find out memory leak?

在此代码中发现泄漏的问题,请帮助我。 提前致谢。 此致

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);

1 个答案:

答案 0 :(得分:1)

如果您正在使用Instruments检测泄漏,请考虑泄漏将显示泄漏内存分配点的事实,而不是实际发生泄漏的位置。

您的代码似乎对我而言。您正确地释放了通过AB方法获得的对象。另一方面,您为contact对象分配了几个ivars。泄漏可能发生在那里,所以还要查看contact的生命周期,或者包含它的任何对象。