SBJsonParser와 관련된 메모리 누수 위치를 찾기 위해 누수를 사용했습니다. 이유가 무엇인지 이해하지 못합니까? 누군가가 통찰력을 발휘할 수 있기를 바랬습니다. 누수는 objectWithURL이라는 메서드에서 누출이 있음을보고합니다. 이 메서드는 downloadJSONFeed라는 메서드에서 호출됩니다. 나는 아래 둘 모두를 보여 줬다.SBJsonParser 메모리 누수
감사합니다.
- (id) objectWithUrl:(NSURL *)url
{
SBJsonParser *jsonParser = [SBJsonParser new];
NSString *jsonString = [self stringWithUrl:url];
// Parse the JSON into an Object
return [jsonParser objectWithString:jsonString error:NULL];
}
- (void) downloadJSONFeed
{
//set up query
NSString *lat = [NSString stringWithFormat:@"%f", ad.locationManager.location.coordinate.latitude];
NSString *lon = [NSString stringWithFormat:@"%f", ad.locationManager.location.coordinate.longitude];
NSString *postValues = [NSString stringWithFormat:@"http://vivid-wind-8436.herokuapp.com/bathrooms/nearby.json/?lat=%@&lon=%@",lat, lon];
//get server response
id response = [self objectWithUrl:[NSURL URLWithString:postValues]];
//store in dictionary
NSDictionary *dictionary = (NSDictionary *)response;
//array for json data
NSMutableArray *jsonData = [[NSMutableArray alloc] init];
for (NSDictionary *dict in dictionary)
{
Bathroom *bathroom = [[[Bathroom alloc] init] autorelease];
bathroom.name = [dict objectForKey:@"name"];
bathroom.street = [dict objectForKey:@"street"];
bathroom.city = [dict objectForKey:@"city"];
bathroom.state = [dict objectForKey:@"state"];
bathroom.postal = [dict objectForKey:@"postal"];
bathroom.country = [dict objectForKey:@"country"];
bathroom.accessibility = [dict objectForKey:@"access"];
bathroom.gendered = [dict objectForKey:@"bathroomtype"];
bathroom.availability = [dict objectForKey:@"avail"];
bathroom.directions = [dict objectForKey:@"directions"];
bathroom.comment = [dict objectForKey:@"comment"];
bathroom.distance = [dict objectForKey:@"distance"];
bathroom.lat = [dict objectForKey:@"lat"];
bathroom.lon = [dict objectForKey:@"lon"];
[jsonData addObject:bathroom];
}
//now sort array by distance
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [jsonData sortedArrayUsingDescriptors:sortDescriptors];
//dataArray = [[NSMutableArray alloc] init];
//add objects to data array
[dataArray addObjectsFromArray:sortedArray];
//release json data
[jsonData release];
}
autorelease가 문제를 해결 한 것으로 보입니다. 고맙습니다. –