Reputation: 3
I've read the Apples docs on memory management and feel I understand them but I can't get this to not leak. In this example I have the process running on the main thread to keep it simple. The first time search button is clicked all works fine, no leaks. Second time search is clicked/perfomed everything works find but instruments displays the following leaks:
Leaked Object # Address Size Responsible Library Responsible Frame
NSCFString,42 < multiple > 1.30 KB CTContacts jk_cachedObjects
NSCFString,16 < multiple > 464 Bytes CTContacts jk_cachedObjects
JKDictionary,7 < multiple > 224 Bytes CTContacts jk_object_for_token
Malloc 288 Bytes,7 < multiple > 1.97 KB CTContacts jk_object_for_token
Malloc 32 Bytes, 0x7859a30 32 Bytes CTContacts jk_object_for_token
JKArray, 0x78599f0 32 Bytes CTContacts jk_object_for_token
it seems to be pointing to this line: (listed as %100)
NSDictionary *resultsDictionary = [jsonData objectFromJSONDataWithParseOptions:JKParseOptionStrict error:(NSError **)error];
I've tried NSDictionary *resultsDictionary =[ [[NSDictionary alloc]init]autorelease]; but with same result.
Below are the two methods involved:
- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {
pickerView.hidden=YES;
searchBar.showsScopeBar=YES;
[searchBar setShowsCancelButton:NO animated:YES];
[searchBar resignFirstResponder];
[self queryWebService];
}
-(void) queryWebService{
NSString *urlAddress = [NSString stringWithFormat:@"http://myweb.com/json.php?lname=%@&searchType=%@",searchBar.text,currentSearchCategory];
NSURL *url = [NSURL URLWithString:urlAddress];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startSynchronous];
NSError *error = [request error];
if (!error){
NSString *responseString = [request responseString];
//NSLog(@"Response: %@", responseString);
NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *resultsDictionary = [jsonData objectFromJSONDataWithParseOptions:JKParseOptionStrict error:(NSError **)error];
if (resultsDictionary)
{
rows = [[resultsDictionary objectForKey:@"contacts"] retain];
resultsDictionary=nil;
}
}
[myTableView reloadData];
}
NSArray "rows" is used as the tableView dataSource. Any help would be appreciated, thanks.
Upvotes: 0
Views: 1679
Reputation: 5831
I'd imagine that rows
is the cause. Each time you run through the loop, you add another retain
to it. Getting rid of the retain
should do the trick and get rid of the memory leak. If for some reason, a retain
is necessary there, you'll just have to find a place elsewhere to release it and keep your retain count at the proper value
Upvotes: 3