问题描述
- 创建zip文件引发泄漏
-
NSData * buffer = [fileHandle readDataOfLength:chunkSize]; while ([buffer length] > 0) { [streamBIG writeData:buffer]; offset += [buffer length]; [fileHandle seekToFileOffset:offset]; buffer = [fileHandle readDataOfLength:chunkSize]; }
这段代码是用来zip大小为25-30MB的批量文件,但是引起了崩溃。
解决方案
试试自动释放:
NSData * buffer = [fileHandle readDataOfLength:chunkSize];
while ([buffer length] > 0)
{
@autoreleasepool
{
[streamBIG writeData:buffer];
offset += [buffer length];
[fileHandle seekToFileOffset:offset];
buffer = [fileHandle readDataOfLength:chunkSize];
}
}
解决方案二:
改成这样试试:
do{
@autoreleasepool
{
NSData * buffer = [fileHandle readDataOfLength:chunkSize];
if ([buffer length] == 0)
break;
[streamBIG writeData:buffer];
offset += [buffer length];
[fileHandle seekToFileOffset:offset];
}
} while (true);
时间: 2025-01-25 11:03:07