Jason Zhao
Jason Zhao

Reputation: 1288

request send get error: [CFString release]: message sent to deallocated instance 0x6a83e00

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?

Upvotes: 2

Views: 990

Answers (1)

Yun
Yun

Reputation: 5463

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.

Upvotes: 1

Related Questions