【问题标题】:NSMutableData appendData: gets reallocated, memory issueNSMutableData appendData:被重新分配,内存问题
【发布时间】:2012-02-01 13:19:25
【问题描述】:

我在我的应用程序上添加了一个进度条。一切都很好,按照我想要的方式运行。但问题是当我将下载的数据附加到 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 中的重新分配吗?

谢谢!!!

【问题讨论】:

  • 您没有显示创建/重新分配 responseData 的代码。显示出来。

标签: iphone cocoa-touch cocoa ipad memory-management


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 2011-01-07
    • 2011-03-18
    相关资源
    最近更新 更多