AlamoFire image memory issue - ios

I use alamofireimage for loading images async and I use AutoPurgingImageCache for caching the loaded images (url request). I have a pull-to-refresh feature in my app and after I do that even if the app content remains the same I see that the app size is increasing and alamofire does not fetch the images from cache and instead it loads them from new requests. Profiling the app reveals that a memory issue exists in alamofire. I have attached the screen shot. I would appreciate if someone has some insight into this.

What cache size did you specify? It's possible that you're experiencing cache misses because the number of distinct images you request per-refresh is more than large enough to fill up the entire cache.
It's also possible that the cache key, i.e. image URL, is changing between refreshes, which could prevent your caching mechanism from correctly looking up cached images.
It's certainly possible there's a problem with AlamoFire, but you should probably start by examining your caching setup for problems like the above.

Related

iOS - Caching Images and Managing Storage

My iOS app is somewhat similar to Facebook in the sense that it will display user generated 'posts' in a scrollable tableview, each with an image to display.
To try and avoid downloading images each time the users scrolls through the tableview, I'm using FTWCache to store each post's image data, as such:
[FTWCache setObject:loadedData forKey:[NSString stringWithFormat:#"postID%#", post.ID]];
Is this a poor practice, to lean heavily on a caching class like this? After awhile, the cache would become considerable in size, should I be flushing it every so often?
If anyone has any advice it would be much appreciated.
I'm not familiar with FTWCache but I can see that it was last maintained 3 years ago while SDWebImage or AFNetworking is maintained daily with a really big community behind it.
I'd go with AFNetworking. You shouldn't worry too much about leaning heavily on caching. That's what it's for. You could however read a bit more about how NSURLCache works and how AFNetworking is using it.
Here's the gist of it:
AFNetworking takes advantage of the caching functionality already
provided by NSURLCache and any of its subclasses. So long as your
NSURLRequest objects have the correct cache policy, and your server
response contains a valid Cache-Control header, responses will be
automatically cached for subsequent requests.

UIImageView UIKit setImageWithURL memory usage

Trying to debug my app, but my memory keeps increasing .
I have an app that pulls JSON from a web service with AFNetworking. I use UIKit + AFNetworking to load the URL string that I got from the JSON in UIImageView which are in a custom XIB table cell. I use setImageForURL.
When I load new JSON and hence new image URL's, my memory usage jumps by 2-7 mb each time. The old images are replaced in the UI by new ones. Live memory usage goes up and up. I've looked into the arrays holding the JSON and so forth - no leaks.
I suspect there is some image caching going on but I've never seen any information regarding image caching when using UIImageView with setImageWithURL. I've seen memory issues using imageNamed though.
Does setImageWithURL have the same memory issues as imageNamed?
setImageWithURL: from AFNetworking handles the caching of the images downloaded with this method. The next time you call this for the same URL it will check the cache first to see if the image is cached (so no need to go network again).
From AFNetworking API:
Asynchronously downloads an image from the specified URL, and sets it
once the request is finished. Any previous image request for the
receiver will be cancelled. If the image is cached locally, the
image is set immediately, otherwise the specified placeholder image
will be set immediately, and then the remote image will be set once
the request is finished. By default, URL requests have a Accept
header field value of "image / *", a cache policy of
NSURLCacheStorageAllowed and a timeout interval of 30 seconds, and
are set not handle cookies. To configure URL requests differently, use
setImageWithURLRequest:placeholderImage:success:failure:
So there is indeed caching, hence memory usage.
Hope it helps.

Optimize image size in Parse.com

I have a strange issue with the resize methods on Parse Image Module:
First I get an image of 3.8MB (1920x1080px) in a Parse Cloud Code, then I resize it to 384x216px.
What I can't figure out is that when I download the resulting image in my front application, the file size is still 3.8MB while the image size reduced as expected.
I can't allow myself to force my users to download images so heavy.
Any suggestions on how to solve this out ?
I am ready to work with an external library as long as it can be executed on Parse Cloud Code.
Do not resize images in the cloud. Resize them on the client and send small files over the web. It takes shorter processing time to resize them in comparison to traveling over the network.
The reason you are seeing the old image in front of your application is probably because parse has an internal cache. Queries that have been sent before load from the cache to lower the amount of transferred data. You can easily observe this by deleting the application and reinstalling, your images will probably work fine.
http://blog.parse.com/2011/09/30/easy-caching-with-parse/
https://www.parse.com/docs/ios_guide#queries-caching/iOS

Configure the delay afnetwork stores images

I want to be able control how much time the image is stored in the cache. This is how i download the image using afnetwork:
[myImageView setImageWithURL:url placeholderImage:placeHolder];
I looked it up in the documentation, i didn't find anything interesting.
any clue?
EDIT: Additional question: is the cache stored in the disk? i guess so because images remain in the cache even after i close the application. but i am not sure.
AFNetworking uses an NSCache instance, which will store more and more images in memory, until a memory warning is received, at which point it will remove some or all of the messages. NSCache does not save to disk.
AFNetworking also uses NSURLCache, which caches URL responses to disk based on (1) your NSURLRequest settings and (2) the cache headers sent by the HTTP server. You can adjust the caching behavior in your app by setting the NSURLRequestCachePolicy, and on your server by setting the cache headers.
If that doesn't give you enough control, you may want to check out SDURLCache, an open source NSURLCache alternative.

app crash when SDWebImageProgressiveDownload

I am using SDWebImage library for fetching and caching images in a table view. However the app crashes due to low memory when i use the option SDWebImageProgressiveDownload.Also the library seems to be slow in downloading images. I dont think its caching them coz every time i request to fetch the same amount of time is taken to download. Has anyone encountered the same problem? Is there a solution for this?

Resources