Note that there are some explanatory texts on larger screens.

plurals
  1. POSolving memory leak in Xcode
    primarykey
    data
    text
    <p>I am trying to do a program on contacts APP using address book and it works fine but when I analyze there are several memory leaks I have managed to minimize the memory leaks and now I am down to 2 main memory leak warning, One in my Address book reload function, I have included comments to show what all things I have tried</p> <pre><code>-(void)reloadAddressBook { //if(self.addressBook) //CFRelease(self.addressBook); self.addressBook = (__bridge ABAddressBookRef) CFBridgingRelease(ABAddressBookCreate()); if(ABAddressBookHasUnsavedChanges(self.addressBook)) { ABAddressBookSave(self.addressBook,NULL); } //if(self.contactAdd) //CFRelease(self.contactAdd); self.contactAdd= ABAddressBookCopyArrayOfAllPeople(self.addressBook); **//Memory warning here and says: call to function ABAddressBookCopyArrayOfAllPeople returns a core foundation object with a +1 retain count** //self.contactAdd= (__bridge ABAddressBookRef) CFBridgingRelease(ABAddressBookCopyArrayOfAllPeople(self.addressBook)); **// If I use this format my memory leak issue solves here but I get error in my program** } - (void)viewDidLoad {**//Memory warning here and says :object leaked :allocated object is not retained lated in this execution path and has retain count +1** [super viewDidLoad]; self.contactSearchBar.delegate=self; self.contactTableView.delegate=self; self.contactTableView.dataSource=self; UIBarButtonItem *addContactButton=[[UIBarButtonItem alloc]initWithTitle:@"Add" style:UIBarButtonItemStyleBordered target:self action:@selector(newContact:)]; self.navigationItem.rightBarButtonItem=addContactButton; self.navigationItem.title=@"My Contacts"; } </code></pre> <p>Another memory leak is in this search bar function</p> <pre><code>-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if(searchText.length==0) { isFiltered=NO; } else { isFiltered=YES; int j=0,i=0; self.filteredData= CFArrayCreateMutable(kCFAllocatorDefault, 0,&amp;kCFTypeArrayCallBacks);**// Memory warning here and says: call to function CFArrayCreateMutable returns a core foundation object with a +1 retain count** for(i=0;i&lt;CFArrayGetCount(self.contactAdd);i++)**//Memory warning here and says :object leaked :allocated object is not retained lated in this execution path and has retain count +1** { self.person=CFArrayGetValueAtIndex(self.contactAdd,i); NSString *str=[[NSString stringWithFormat:@"%@", (__bridge_transfer NSString *)ABRecordCopyValue(self.person, kABPersonFirstNameProperty)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; NSRange contactRange= [str rangeOfString: searchText options:NSCaseInsensitiveSearch]; NSLog(@"i=%d, j=%d",i,j); if(contactRange.location!=NSNotFound) { CFArrayInsertValueAtIndex(self.filteredData,j++,self.person); CFArrayGetValueAtIndex(self.filteredData,j-1); } } //CFRelease(self.contactAdd); //CFRelease(self.filteredData); } </code></pre> <p>Memory leak show on for loop statement and it says: </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload