我有以下方法
-(void)request
{
responseData = [[NSMutableData data] retain];
NSString *post = [NSString stringWithFormat:@"id=%d&a_id=&d",1,1];
NSLog(@"%@",post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:kWebURL@"/req/request.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
[postLength release];
[postData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
}我的问题是nsmutableurlrequest对象有一个漏洞。我想我应该在某个地方发布它,但是当我尝试这样做的时候,我得到了一个exec_bad_access。每当我尝试释放它时,在connectionDidFinishLoading方法的末尾都会得到这个错误。
编辑:看起来我既可以释放NSURLConnection对象,也可以释放NSMutableURLConnection对象。
如果我在应该删除它们时尝试将它们都删除,则会得到exec_bad_access
发布于 2010-02-21 05:25:51
我相信你的问题在于你发布了postLength和postData。您没有分配这两个方法中的任何一个,但是使用方便的方法创建了它们。你应该去掉这两行代码,然后就可以释放你的NSMutableURLRequest了。
https://stackoverflow.com/questions/2303747
复制相似问题