看板 MacDev 關於我們 聯絡資訊
在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)
yllan:try [pool drain]? 06/08 12:26
lemonstar:sorry修到推文.. 06/08 12:28
lemonstar:好像還是一樣ㄟ.. 06/08 12:34