2011-05-20 23 views
0

我正在使用以下方法一次讀取一行文本(總共110萬行)的文本文件,並且模擬器上我的應用程序的內存佔用增長到文本文件的總文件大小(480MB)。我是否需要實施自動釋放池來管理內存消耗?iOS內存泄漏NSFilehandle逐行文件讀取器

How to read data from NSFileHandle line by line?

NSString *docDir = [AppSession documentsDirectory]; 
NSString *csvpath = [docDir stringByAppendingPathComponent:@"/docs/output.csv"]; 

__block NSUInteger count = 0; 

DDFileReader * reader = [[DDFileReader alloc] initWithFilePath:csvpath]; 
[reader enumerateLinesUsingBlock:^(NSString * line, BOOL * stop) 
{ 
    count++;  
}]; 

NSLog(@"FINAL COUNT %i", count); 
[reader release]; 

回答

0

是。它必須位於您的DDFileReader類中,在enumerateLinesUsingBlock:的循環中。你不能從你在這裏發佈的代碼中正確地做到這一點。

+0

我在while語句中添加了一個autorelease池,這並沒有幫助。 while(stop == NO &&(line = [self readLine])){NSAutoreleasePool * readPool = [[NSAutoreleasePool alloc] init]; block(line,&stop); [readPool drain]; } – VinnyD 2011-05-20 05:34:00