简体   繁体   English

使用GoldRaccoon下载大文件时的内存压力(ftp库)

[英]Memory pressure while downloading a large size file using GoldRaccoon(ftp library)

I use GoldRaccoon as my 3rd ftp library. 我使用GoldRaccoon作为我的第3个ftp库。 When I download large size (> 500MB) file, my app will crash in memory pressure. 当我下载大文件(> 500MB)时,我的应用程序将因内存不足而崩溃。

The snapshot as below that using instrument to detect the memory allocations in my app. 下面的快照使用工具来检测我的应用程序中的内存分配。

在此处输入图片说明

在此处输入图片说明

It seems self.receivedData takes too much memory allocations. 似乎self.receivedData占用了过多的内存分配。 How do I handle these allocation when getting low memory warning ?? 收到内存不足警告时如何处理这些分配?

I know this is old but I was just dealing with the exact same thing and I'm sure someone else is too. 我知道这已经很老了,但我只是在处理完全相同的事情,我敢肯定其他人也是如此。 It's very easy to fix, not sure why it wasn't implemented like this in the first place. 它很容易修复,不确定最初为什么没有实现它。

In GRRequestsManager.m, replace this method with this. 在GRRequestsManager.m中,将此方法替换为此。

- (void)dataAvailable:(NSData *)data forRequest:(id<GRDataExchangeRequestProtocol>)request
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:[request localFilePath]])
    {
        [data writeToFile:[request localFilePath] atomically:YES];
    }
    else
    {
        NSFileHandle *handle = [NSFileHandle fileHandleForUpdatingAtPath:[request localFilePath]];
        [handle seekToEndOfFile];
        [handle writeData:data];
        [handle closeFile];
    }
}

Then in the - (void)requestCompleted:(GRRequest *)request method, remove the writing to file in the download section. 然后,在-(void)requestCompleted:(GRRequest *)request方法中,删除下载部分中对文件的写入。 That's it, now instead of storing the file up in NSData and writing at the end, it just keeps adding the data to the file as it goes. 就是这样,现在它不再将文件存储在NSData中并在末尾写入文件,而是继续将数据添加到文件中。 I didn't take the time to make it pretty or handle write errors, but it works. 我没有花时间使它漂亮或处理写错误,但是它可以工作。

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

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