简体   繁体   English

NSFilehandle逐行文件读取器上的iOS内存泄漏

[英]iOS Memory Leak on NSFilehandle line-by-line File Reader

I'm using the following method of reading a text file one line at a time (1.1 million total lines) and the memory footprint of my app on the simulator grows to the total filesize of the text file (480MB). 我正在使用以下方法一次读取一行文本文件(共110万行),并且我的应用程序在模拟器上的内存占用量增长到文本文件的总文件大小(480MB)。 Do I need to implement an autorelease pool drain to manage the memory consumption? 我是否需要实现自动释放池消耗来管理内存消耗?

How to read data from NSFileHandle line by line? 如何从NSFileHandle逐行读取数据?

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];

Yes. 是。 It would have to be in your DDFileReader class, inside the loop in enumerateLinesUsingBlock: . 它必须在您的DDFileReader类中,在enumerateLinesUsingBlock:的循环内。 You cannot correctly do it from the bit of code you have posted here. 您无法从此处发布的代码中正确地做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM