我正在使用JSONConnection
对象,如下所示。
- (void)startGettingSearchResultsByKeyword:(NSString *)keyword
delegate:(id <DataProviderDelegate>)delegate
{
/* Prepare request */
JSONConnection *jsonConnection = [[JSONConnection alloc] initWithURLString:NSLocalizedString(@"GET_SEARCH_RESULTS", nil)];
[jsonConnection.requestValues setObject:APP_VERSION_VALUE forKey:APP_VERSION_KEY];
[jsonConnection.requestValues setObject:keyword forKey:KEYWORD_KEY];
/* Send asynchronnous URL request and process response */
[jsonConnection sendAsynchronousRequestWithCompletionHandler:^(NSDictionary *responseValues, NSError *error) {
NSArray *responseDataArray = [[responseValues objectForKey:JSON_RESPONSE_DICTIONARY_KEY] JSONValue];
NSMutableArray *searchResults = [[NSMutableArray alloc] init];
if ([responseDataArray count] > 0) {
for (int index = 0; index < [responseDataArray count]; index++) {
NSDictionary *result = [responseDataArray objectAtIndex:index];
ProductDetails *searchResult = [[ProductDetails alloc] init];
NSNumber *contentId = [result objectForKey:NSLocalizedString(@"CONTENT_ID", nil)];
searchResult.contentId = [NSString stringWithFormat:@"%d", [contentId intValue]];
searchResult.productName = [result objectForKey:NSLocalizedString(@"NAME", nil)];
[searchResults addObject:searchResult];
[searchResult release];
}
}
[delegate didFinishGettingSearchResults:searchResults];
[searchResults release];
}];
}
我不知道
release
我的JSONConnection
对象的正确位置。请帮忙。
最佳答案
分配时是否尝试过自动释放JSONConnection?
JSONConnection *jsonConnection = [[[JSONConnection alloc] initWithURLString:NSLocalizedString(@"GET_SEARCH_RESULTS", nil)] autorelease];