如何释放JSONConnection对象

时间:2012-03-30 06:47:07

标签: ios objective-c memory-management memory-leaks

我正在使用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对象的正确位置。

请帮忙。

1 个答案:

答案 0 :(得分:1)

您是否尝试在分配JSONConnection时自动释放它?

JSONConnection *jsonConnection = [[[JSONConnection alloc] initWithURLString:NSLocalizedString(@"GET_SEARCH_RESULTS", nil)] autorelease];