请求发送获取错误:[CFString release]:消息发送到已释放的实例 0x6a83e00
我想检查苹果的应用程序版本,因此我
- (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 方法,那么就没有任何问题。 有死吗?
I want to check the app version from apple so I send request like below
- (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];
}
}
and after [_request send]; will get [CFString release]: message sent to deallocated instance 0x6a83e00. I checked all Strings in this method seems they are ok, and I can still get correct response from remote.
If I comment out this connectToCheckVersion method then no any problem.
Any diea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该保留 _request 变量并将其保存为成员。
因为函数返回后会自动释放。
请求成功或失败后都必须释放它。
谢谢。
I think that you should retain the _request variable and save it as a member.
Because it will autorelease after the function is returned.
You have to release it after the request is successed or failed.
Thank you.