1
我正在使用JSONConnection
對象,如下所示。如何釋放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
對象的想法。
請幫忙。
Nop。我沒有。所以,我添加了autorelease並且工作正常。謝謝。 – chinthakad 2012-03-30 09:34:35