简体   繁体   English

CFNetwork下载图像时占用大量内存

[英]CFNetwork large memory footprint while downloading images

First, I'm not exactly sure if this is an AFNetworking problem or CFNetwork. 首先,我不确定这是AFNetworking问题还是CFNetwork。

I am using AFNetworking in an iOS app that downloads thousands of images. 我在下载成千上万张图片的iOS应用中使用AFNetworking。 This is implemented via NSMutableURLRequest, AFHTTPRequestOperation (with a AFHTTPResponseSerializer), NSOperationQueue (The maxConcurrentOperationCount on the NSOperationQueue is set to 8 btw). 这是通过NSMutableURLRequest,AFHTTPRequestOperation(带有AFHTTPResponseSerializer),NSOperationQueue(NSOperationQueue上的maxConcurrentOperationCount设置为8 btw)来实现的。

what i'm seeing is that while these images are downloading from the server, the memory footprint of my app goes up significantly. 我所看到的是,当这些图像从服务器下载时,我的应用程序的内存占用显着增加。 Using allocations in instruments (XCode5), it looks like a lot of the memory goes to CFData in HTTPProtocol::bytesAvailable in CFNetwork. 使用工具(XCode5)中的分配,看起来很多内存都流向了CFNetwork中的HTTPProtocol :: bytesAvailable中的CFData。

在此处输入图片说明

While i don't know anything about CFNetwork, i am just speculating that while images are downloading, some CFData is not being released, which leads to the temporary accumulation of a lot of memory. 虽然我对CFNetwork一无所知,但我只是在猜测正在下载映像时,某些CFData并未释放,这导致了大量内存的临时积累。

Just to be clear, this memory is eventually released, somewhere, somehow, as i see the memory footprint go down in Instruments after a while, but what I'm concerned abut is whats going on while the images download. 需要明确的是,该内存最终以某种方式释放,在某种程度上,正如我看到一段时间后在Instruments中的内存占用量下降一样,但是我担心的是图像下载时发生了什么。

在此处输入图片说明

The strange things is that with maxConcurrentOperationCount=8, you would think that no more than 8 images are downloaded at any one time... 奇怪的是,在maxConcurrentOperationCount = 8的情况下,您可能认为一次最多只能下载8张图像...

Is this an issue that others have come across and if so, how to fix it? 这是其他人遇到的问题吗?如果是,如何解决? can AFNetworking be configured in a way so this doesn't happen? 可以以某种方式配置AFNetworking以免发生这种情况吗?

Thanks. 谢谢。

AFNetworking具有操作队列,您可以如下设置最大并发操作数:

[[requestOperationManager operationQueue] setMaxConcurrentOperationCount:5];

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

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