2 developerwab developerWab 于 2013.03.21 11:03 提问

创建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的批量文件,但是引起了崩溃。

2个回答

gaoXxxing
gaoXxxing   2013.03.21 11:30
已采纳

试试自动释放:

           NSData * buffer = [fileHandle readDataOfLength:chunkSize];
            while ([buffer length] > 0)
            {
                @autoreleasepool
                {
                [streamBIG writeData:buffer];
                offset += [buffer length];

                [fileHandle seekToFileOffset:offset];
                buffer = [fileHandle readDataOfLength:chunkSize];
                }
            }
dream238
dream238   2013.03.22 09:29

改成这样试试:

do{
@autoreleasepool
{
NSData * buffer = [fileHandle readDataOfLength:chunkSize];
if ([buffer length] == 0)
break;
[streamBIG writeData:buffer];
offset += [buffer length];
[fileHandle seekToFileOffset:offset];
}
} while (true);

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!