Find out memory leak?
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);
精彩评论