Reputation: 81
I'm making an app which will fetch pictures resources and text from web service. I pick the great AFNetworking's UIImageView+AFNetworking category to deal with the image downloading stuff.
However, I'm facing a memory problem. I used Allocation tool of the Instruments, finding each time I load more images, there will always be a growth of memory allocation, 1-2 MB in size. I tracked down to the source code, it turned out that it lies in AFNetworking's code.
The exact line of code is:
- (void)connectionDidFinishLoading:(NSURLConnection *)__unused connection {
self.responseData = [self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
[self.outputStream close];
[self finish];
self.connection = nil;
}
This will occupy 99.6% of the memory allocation.
I user ARC in the project, display the UIImageViews in a UITableView and configure the cell like the following code:
[self.imageView setImageWithURLRequest:request
placeholderImage:nil
success:successBlock
failure:failBlock];
Can any one offer some idea about the memory issue? It's really a headache cuz once the memory is allocated, they will never be cleared even if I cleared the whole image view. After a little while, my app will occupy more than 100MB from the Real Memory Usage window of Instruments.
Any help will be greatly appreciated!! Thanks in advance!!
Upvotes: 5
Views: 1252
Reputation: 296
It is possible to clear the cache of images. There is a discussion about it on github here:
That may or may not solve your problem. I would imagine clearing the cache on a regular basis should keep your memory usage down though.
Upvotes: 0