请求发送获取错误:[CFString release]:发送到解除分配的实例0x6a83e00的消息

时间:2011-10-20 10:01:48

标签: iphone objective-c ios three20

我想检查苹果的应用版本,所以我发送如下的请求

- (void)connectToCheckVersion{
NSString *url = @"http://itunes.apple.com/lookup?id=466424846";
TTURLRequest *_request = [TTURLRequest requestWithURL:url delegate:self];
_request.httpMethod = @"GET";
_request.cachePolicy = TTURLRequestCachePolicyNone;
_request.shouldHandleCookies = NO;
TTURLJSONResponse* response = [[TTURLJSONResponse alloc] init];
_request.response = response;
TT_RELEASE_SAFELY(response); 
[_request send];
}


- (void)requestDidFinishLoad:(TTURLRequest*)request {
    TTURLJSONResponse* response = request.response;
    NSDictionary* json = response.rootObject;

    NSArray *results = [json objectForKey:@"results"];
    NSString *version;
    for (NSDictionary *rawResult in results) {

        version = [rawResult objectForKey:@"version"];
    }
    NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
    if (version != nil && currentVersion != nil && ![version isEqualToString:currentVersion]) {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"info" 
                                                        message:@"newer version" 
                                                       delegate:self 
                                              cancelButtonTitle:@"ok"
                                              otherButtonTitles:nil, nil];
        [alert show];
        [alert release];

    }

}

和[_request send]之后;将获得[CFString release]:消息发送到解除分配的实例0x6a83e00。我检查了这个方法中的所有字符串似乎没问题,我仍然可以从远程获得正确的响应。

如果我注释掉这个connectToCheckVersion方法,那么没有任何问题。 任何迪亚?

1 个答案:

答案 0 :(得分:1)

我认为你应该保留 _request 变量并将其保存为成员。 因为在返回函数后它会自动释放

您必须在请求成功或失败后将其释放。

谢谢。