我正在處理一個應用程序,並且有1個泄漏。 泄漏的對象是NSAutoreleasePool,大小是32字節。 在堆棧跟蹤中,只調用基礎方法。 我不知道如何解決這個問題。泄漏NSAutoreleasePool
在模擬器沒有泄漏報告,在設備上只有這個泄漏。
任何想法的?
autoreleasepool是我自己定義的一個。
在我的ViewController我打電話:
[self performSelectorInBackground:@selector(getDetailInfo:) withObject:self.infoID];
這是getDetailInfo:
- (void)getDetailInfo:(NSString *)theID {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
DetailInfo *info = [[DataProvider sharedInstance] getDetailInfo:theID]; //the return object is autoreleased.
[self performSelectorOnMainThread:@selector(updateViewWithDetailInfo:) withObject:info waitUntilDone:NO];
[pool release];
}
一些額外的信息:
爲了測試我改變了我的所有方法其使用performSelectorInBackground運行叫在主線程上,並刪除那些autoreleasepools。
我仍然收到NSAutoreleasePool泄漏。今天我瞭解到,您可以在樂器中的堆棧跟蹤中顯示「庫名稱」。 :-)我複製它的下方,你可以看到線6和7
0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 Foundation +[NSAutoreleasePool allocWithZone:]
5 CoreFoundation +[NSObject(NSObject) alloc]
6 MapKit TileCachePrivate::runCacheThread()
7 MapKit _runCacheThread(void*)
8 libSystem.B.dylib _pthread_start
9 libSystem.B.dylib thread_assign_default
本作的MapView代碼的MapKit:
MKMapView *omgeving = [[MKMapView alloc] initWithFrame:CGRectMake(11, 22, 298, 297)];
omgeving.delegate = nil;
[self addSubview:omgeving];
[omgeving release];
如果我註釋掉的MapView碼,無泄漏。如果我把它放進去,我會得到泄漏。
Leaked Object # Address Size Responsible Library Responsible Frame
NSAutoreleasePool 0x6a52e50 32 Foundation +[NSAutoreleasePool allocWithZone:]
感謝您所有的評論到目前爲止。 有什麼建議嗎?
autorelease池在哪裏?這是main.m中的嗎?或者它是你自己定義的一個。如果是這種情況,則需要在完成時消除或釋放自動釋放池。 – DHamrick 2010-11-11 16:24:41
DHamrick是對的。你能告訴我們你正在分配你正在泄漏的池的代碼,以及你正在耗盡它的地方嗎? – Ryan 2010-11-11 16:30:24
我已編輯帖子以包含autoreleasepool的代碼。 – McDJ 2010-11-11 16:41:31