创建zip文件时创建泄漏的大量大文件

时间:2013-03-20 08:57:49

标签: iphone ios objective-c zip

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

                    [fileHandle seekToFileOffset:offset];
                    buffer = [fileHandle readDataOfLength:chunkSize];
                }

我使用这些特定的进程来压缩超过1个25 - 30 MB的文件,但是这些增加了内存,即实时字节不断增加,直到所有文件都没有写入,因为我的应用程序崩溃了

1 个答案:

答案 0 :(得分:2)

尝试使用自动发布池

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

                    [fileHandle seekToFileOffset:offset];
                    buffer = [fileHandle readDataOfLength:chunkSize];
                    }
                }

它会起作用......