我有一个奇怪的错误,我似乎找不到任何文档或帖子。当我尝试使用标准的教科书方法连接到我的web服务(为了保护隐私而更改了网址)时,我在NSURLConnection initWithRequest上收到EXC_BAD_INSTRUCTION或EXC_BAD_ACCESS。
最奇怪的是,有时我可以毫无例外地跨过这条令人不快的线,但10次中有9次会导致这个错误。有什么建议吗?
- (void)viewDidLoad {
NSURL *url = [NSURL URLWithString:@"http://heres/where/my/webservice/url/is/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
// cancel any old connection
if(connection) {
[connection cancel];
[connection release];
}
// create new connection and begin loading data
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(connection) {
// if the connection was created correctly, release old data (if any), and alloc new
[data release];
data = [[NSMutableData data] retain];
}
[url release];
[request release];
}任何帮助或建议或RTFMs将不胜感激!
发布于 2009-11-20 14:15:59
您正在释放自动释放的对象:
NSURL *url = [NSURL URLWithString:@"…"];
NSURLRequest *request = [NSURLRequest requestWithURL:url …];
// …
[url release];
[request release];我认为Clang应该能够捕捉到这些,参见Build→Build→Analyze (Cmd-Shift-A)。当当是你的朋友,习惯它吧。
https://stackoverflow.com/questions/1768638
复制相似问题