【问题标题】:request send get error: [CFString release]: message sent to deallocated instance 0x6a83e00request send get error: [CFString release]: message sent to deallocated instance 0x6a83e00
【发布时间】:2011-10-20 10:01:47
【问题描述】:

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

- (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]: message sent to deallocated instance 0x6a83e00。我检查了这个方法中的所有字符串,似乎它们都没有问题,我仍然可以从远程得到正确的响应。

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

【问题讨论】:

  • 这里有 2 条建议。 - 您在 requestWithURL 中传递了一个字符串。通常是 [urlWithString:yourURLString]; - 不要自动发布响应。将其分配给_request,然后释放它。
  • k,我更新了上面的代码还是不行,同样的问题...
  • 问题是我可以从远程得到正确的响应。
  • 有没有可能是我需要 URL itunes.apple.com/lookup?id=466424846,响应缺少一些必要的信息?

标签: iphone objective-c ios three20


【解决方案1】:

我认为您应该保留 _request 变量并将其保存为成员。 因为函数返回后会autorelease

请求成功或失败后,你必须释放它。

谢谢。

【讨论】:

    猜你喜欢
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 2012-08-11
    • 2013-07-03
    • 2012-11-17
    相关资源
    最近更新 更多