开发者

Find out memory leak?

开发者 https://www.devze.com 2023-03-20 04:38 出处:网络
i am new on iphone apps.Now this is my first app,app is installed but not run? I write this code it shows memory leak.please find out.Thanks in advance.

i am new on iphone apps.Now this is my first app,app is installed but not run? I write this code it shows memory leak.please find out.Thanks in advance.

ABRecordRef ref = CFArrayGetValueAtIndex(all, i);

CFStringRef *firstName = (CFStringRef *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
NSLog(@"Name %@", firstName);
contact.strFirstName = (NSString*)firstName;

CFStringRef *lastName = (CFStringRef *)ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSLog(@"Name %@", lastName);
contact.strLast开发者_如何学运维Name = (NSString*)lastName;
contact.contactName = [NSString stringWithFormat:@"%@ %@",(NSString *)firstName,lastName];
NSLog(@"Name %@", contact.contactName);

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


You are using ABRecordCopyValue on firstName and lastName which means you need to CFRelease those as well.


CFRelease is a way to go (as @Joe and @jamapag already answered).. I would just like to add that XCode has few nice features like cmd + shift + a gives u a static memory analyser.. And you can also use run -> run w/ performance tools and then use allocations or leaks to analyse our memory management dynamically.


You need to add:

CFRelease(firstName);
CFRelease(lastName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号