ios - 如何释放 JSONConnection 对象

标签 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 对象的正确位置。

请帮忙。

最佳答案

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

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

关于ios - 如何释放 JSONConnection 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938194/

相关文章:

ios - IBOutlets 和内存管理

iphone - iPad 应用程序仅在手动启动(从跳板)时才会崩溃。怀疑内存问题

ios - 哪些 iOS 版本让您无需手动管理内存即可进行开发?

ios - SKSpriteNode 返回空名称

ios - 范围(0...4)和 substringWithRange?

iOS 构建失败;/bin/sh 没有这样的文件或目录

iphone - XMPP 框架接收的最大消息数

ios - 在没有 Game Center 的 iOS 应用程序中实现成就

ios - Apple Notes 应用的共享扩展未激活

iphone - 应用在关闭时不会自动关闭