對於程序下面我得到在線分配的對象的以下無錯誤 潛在泄漏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如何在頭文件中聲明? –
我在我的問題中編輯了它。仔細檢查一下 –
不知道問題出在哪裏。需要更多的代碼。 –