我正在使用这段代码,但是在分析时,它告诉我在response_error
,request
和_response
变量中有很多内存泄漏。
我尝试了几个地方来放置release
函数中使用的每个变量的代码,但它也不断崩溃,有和没有错误消息。(最常见的是EXC_BAD_ACCESS
它指向内存访问错误)
我认为这可能是NSURLConnection sendSynchronousRequest
方法的问题,但我不确定。
有人可以给我一个建议或release
在此代码的正确位置放置块吗?
谢谢
NSString *request_url = [NSString stringWithFormat:@"http://www.server.com/api/arg1/%@/arg2/%@/arg3/%@",self._api_key,self._device_id,self._token];
NSURL *requestURL = [NSURL URLWithString:request_url];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:requestURL];
NSError *response_error = [[NSError alloc] init];
NSHTTPURLResponse *_response = [[NSHTTPURLResponse alloc] init];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&_response error:&response_error];
NSString *str_response = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
return [[str_response JSONValue] valueForKey:@"pairing"];
变量定义如下
@interface MyClass : NSObject {
NSString *_device_id;
NSString *_token;
NSString *_api_key;
}
@property (nonatomic,retain) NSString *_device_id;
@property (nonatomic,retain) NSString *_api_key;
@property (nonatomic,retain) NSString *_token;