주소록을 사용하여 APP에 연락처 프로그램을 보내려고했지만 잘 작동하지만 메모리 누수가 몇 개있는 것으로 분석 할 때 메모리 누수를 최소화 할 수 있었고 현재는 2 개로 줄었습니다 메모리 누수 경고, 내 주소록 다시로드 기능의 하나는, 내가 또 다른 메모리 누수가이 검색 창 기능Xcode에서 메모리 누수 해결
-(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,&kCFTypeArrayCallBacks);**// Memory warning here and says: call to function CFArrayCreateMutable returns a core foundation object with a +1 retain count**
for(i=0;i<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);
}
메모리 누수 쇼에
-(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;
[email protected]"My Contacts";
}
시도할지 모든 것을 보여 주석을 포함했다 for 루프 문과 그것에 대해 말하기 :
이 질문과 매우 유사합니다 : http://stackoverflow.com/questions/18010276/potential-memory-leak-abaddressbookcopyarrayofallpeople – borrrden
"할당 된 객체가이 실행 경로에 저장되지 않았습니다"라고 말했을 때 당신은 "참조"또는 아마도 "발표"를 의미합니까? 이미 +1을 가지고 있다면 그것을 지킬 것을 제안 할 이유가 없습니다. (일반적으로, 이슈 탐색기에서 경고를 복사하여 붙여 넣기를 시도하는 대신 복사하십시오.) –
"이 형식을 사용하면 메모리 누수 문제가 해결되지만 프로그램에 오류가 발생합니다"오류가 있습니까? –