[英]Why I use NSFileHandle read file line by line,the memory usage grows higher and higher?
[英]iOS Memory Leak on NSFilehandle line-by-line File Reader
我正在使用以下方法一次读取一行文本文件(共110万行),并且我的应用程序在模拟器上的内存占用量增长到文本文件的总文件大小(480MB)。 我是否需要实现自动释放池消耗来管理内存消耗?
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];
是。 它必须在您的DDFileReader类中,在enumerateLinesUsingBlock:
的循环内。 您无法从此处发布的代码中正确地做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.