gpt4 book ai didi

iphone - NSMutableData追加数据: gets reallocated,内存问题

转载 作者:行者123 更新时间:2023-12-03 17:42:37 24 4
gpt4 key购买 nike

我在我的应用程序上添加了进度条。一切都很好,按照我想要的方式运行。但问题是,当我将下载的数据附加到 didReceivedData: 中时,我的 responseData 被重新分配,从而使我的应用程序消耗太多内存。然后收到MemoryWarning后崩溃。

   -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//response data is getting reallocated with bigger size of data
[responseData appendData:data];
NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
float progress = [curLength floatValue] / [filesize floatValue] ;
progressView.progress = progress;
}

这里有人可以帮助我如何摆脱响应数据中的重新分配吗?

谢谢!!!

最佳答案

创建 responseData 时,使用 initWithCapacity: 提示您需要多少字节(可以从响应 header 中检索预期的内容长度)。

关于iphone - NSMutableData追加数据: gets reallocated,内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com