[問題] leak of NSThread

看板MacDev作者 (筆記本)時間16年前 (2009/06/08 12:11), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/2 (看更多)
在Stanford教學中 http://www.stanford.edu/class/cs193p/cgi-bin/index.php 有篇NSThrad的Sample : Lecture 10 - LetsMakeAThread Sample Code連結 : http://www.stanford.edu/class/cs193p/downloads/10-LetsMakeAThread.zip 他的架構大致如下 : 1. Thread進入點: [NSThread detachNewThreadSelector:@selector(someFunction) toTarget:self withObject:nil]; (說明文件有提到,"detachNewThreadSelector:.." method中, selector function 必須自訂一個autoreleasepool ) 2.someFunction 內容: (沒忘了加autoreleasepool) -(void)someFunction{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [NSThread sleepforTimeInterval:3]; [self performSelectorOnMainThread:@selector(finishFunction) withObject:nil waitUntilDown:NO]; [pool release]; } 3.end: -(void)finishFunction{ ................... } 問題來了,當我把它放上實機跑Insttrument,就出現一根memory leaks (General Block - 3584) 情形大致就與這篇論壇的情形一樣(有畫面) http://0rz.tw/4SViG 用這個method去啟動新的NSThread,每啟動一個都會出現memory leak... 不知有無解決之道 :( -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.227.51 ※ 編輯: lemonstar 來自: 220.128.227.51 (06/08 12:26)

06/08 12:26, , 1F
try [pool drain]?
06/08 12:26, 1F

06/08 12:28, , 2F
sorry修到推文..
06/08 12:28, 2F

06/08 12:34, , 3F
好像還是一樣ㄟ..
06/08 12:34, 3F
文章代碼(AID): #1AB8zxDK (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1AB8zxDK (MacDev)