对于程序下面我得到在线分配的对象的以下无错误 潜在泄漏50. 线50个指向此line-- self.receivedData = [[NSMutableData数据]保留]; 我试图在此语句后释放receiveData,但是这给了我一个错误“object sent autorelease too much times。”我不知道我是否按照正确的方式去做。请帮忙!Objective-C的对象的泄漏误差
- (void)viewDidLoad {
NSURLRequest *theRequest =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://{your ip}:8080/activiti-rest/service/process-definitions?start=0&size=10&sort=id&order=asc"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
self.receivedData = [[NSMutableData data] retain];
} else {
UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[connectFailMessage show];
[connectFailMessage release];
}
[theConnection autorelease];
}
编辑:在头文件被宣布为@property(nonatomic,assign) NSMutableData *receivedData;
新 它的工作原理之后,我删除了这条线[theConnection自动释放。我把头像文件中的assign属性保留下来,并像你问的那样添加了[self.receiveData release]。它之前没有工作,因为我保留了这一行[theConnection autorelease]。我添加了它,因为我想知道如果我不得不也可以释放连接对象。请你解释为什么不必发布它?它不会在代码中的任何地方发布,它仍然有效?
receivedData如何在头文件中声明? –
我在我的问题中编辑了它。仔细检查一下 –
不知道问题出在哪里。需要更多的代码。 –