ios - Crash when CFRelease(CFArrayRef) -


i have method clear adress book in device. method below.

-(void) clearadressbook {     abaddressbookref addrbook=abaddressbookcreate();     cfarrayref groups = abaddressbookcopyarrayofallgroups(addrbook);     if(groups)     {         cfindex numgroups = cfarraygetcount(groups);         for(cfindex idx=0; idx<numgroups; ++idx)         {             abrecordref groupitem = cfarraygetvalueatindex(groups, idx);                  cfarrayref people=                 abgroupcopyarrayofallmembers(groupitem);                 if(people)                 {                     cfindex peoplecount=cfarraygetcount(people);                     for(cfindex ind=0;ind<peoplecount;++ind)                     {                         abrecordref person=cfarraygetvalueatindex(people, ind);                         abaddressbookremoverecord(addrbook, person, nil);                         abaddressbooksave(addrbook, null);                         cfrelease(person);                     }                     cfrelease(people);//crash                 }              }         }      cfrelease(groups); } 

when i'm releasing cfarrayref application crashes, wrong here? know have release objected returned cf methods names contains copy or create right ?

you over-releasing here "person" object. infact person retrieved array , follows "get rule" you're not owner of , cannot release (or: can first retain , release if you're not sure of object life span). @ end of for-loop when release "people", array tries release internal objects ("people") have been over-releases , leads crash.

so try remove cfrelease(people) statement or, safety, add cfretain(people) after fetch person array (but don't remove cfrelease(people) instruction).


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -