ios - ABAddressBook memory leak -


i trying interact abaddressbook, when analysing code in xcode have memory leak warnings cannot resolve. warnings "potential leak of object" , "potential leak of object stored 'allcontacts'"

+ (void)addnewcontact:(businesscard *)contact { abaddressbookref addressbookref = abaddressbookcreatewithoptions(null, nil); abrecordref newcontact = abpersoncreate(); if (contact.firstname) abrecordsetvalue(newcontact, kabpersonfirstnameproperty, (__bridge cfstringref)contact.firstname, nil); if (contact.familyname) abrecordsetvalue(newcontact, kabpersonlastnameproperty, (__bridge cfstringref)contact.familyname, nil); if (contact.company) abrecordsetvalue(newcontact, kabpersonorganizationproperty, (__bridge cfstringref)contact.company, nil); if (contact.jobtitle) abrecordsetvalue(newcontact, kabpersonjobtitleproperty, (__bridge cfstringref)contact.jobtitle, nil); if (contact.emailaddress) {     abmutablemultivalueref multiemail = abmultivaluecreatemutable(kabmultistringpropertytype);     abmultivalueaddvalueandlabel(multiemail, (__bridge cftyperef)(contact.emailaddress), kabworklabel, null);     abrecordsetvalue(newcontact, kabpersonemailproperty, multiemail, null);     cfrelease(multiemail); }  if (contact.details) abrecordsetvalue(newcontact, kabpersonnoteproperty, (__bridge cfstringref)contact.details, nil);   if (contact.phone) {     abmutablemultivalueref phonenumbers = abmultivaluecreatemutable(kabmultistringpropertytype);     abmultivalueaddvalueandlabel(phonenumbers, (__bridge cfstringref)contact.phone, kabpersonphonemainlabel, null);     abrecordsetvalue(newcontact, kabpersonphoneproperty, phonenumbers, nil);     cfrelease(phonenumbers); }  abaddressbookaddrecord(addressbookref, newcontact, nil); cfrelease(newcontact);  nsarray *allcontacts = (__bridge nsarray *)abaddressbookcopyarrayofallpeople(addressbookref); (id record in allcontacts){     abrecordref thiscontact = (__bridge abrecordref)record;     if (cfstringcompare(abrecordcopycompositename(thiscontact), abrecordcopycompositename(newcontact), 0) == kcfcompareequalto){         [[[uialertview alloc] initwithtitle:nslocalizedstring(@"existing contact", @"title alert view when adding existing contact") message:nslocalizedstring(@"a contact exists same name. want add new contact?", @"message alert view when adding existing contact")                            cancelbuttonitem:[ributtonitem itemwithlabel:nslocalizedstring(@"no", @"no")]                            otherbuttonitems:[ributtonitem itemwithlabel:nslocalizedstring(@"yes", @"yes")   action:^{             [self saveinaddressbook:addressbookref];         }], nil] show]; //potential leak of object          nslog(@"contact exists");         return;     }  }  [self saveinaddressbook:addressbookref]; //potential leak of object stored 'allcontacts' cfrelease(addressbookref); nslog(@"contact created"); }  + (void)saveinaddressbook:(abaddressbookref)addressbookref {     abaddressbooksave(addressbookref, nil);     [[[uialertview alloc] initwithtitle:nslocalizedstring(@"contact added", @"title alert view when contact added address book") message:nil delegate:nil cancelbuttontitle:nslocalizedstring(@"ok", @"ok") otherbuttontitles:nil] show]; } 

does know how can fix these issues?

you forgot

cfrelease((__bridge cftyperef) allcontacts); 

i think can put this:

for (id record in allcontacts){     ... }  cfrelease((__bridge cftyperef) allcontacts); [self saveinaddressbook:addressbookref]; //potential leak of object stored 'allcontacts' cfrelease(addressbookref); nslog(@"contact created"); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -