I am trying to understand how the UIWebView cache works. Since my goal is to be able to manage the memory allocated by the UIWebView (at least as much as possible), in order to avoid expanding the memory size indefinitely, and because of this, the application will be killed because of this.
After reading another stackoverflow questions and searching the web , I decided to try NSURLCache sharedURLCache , but I can't figure out how this works.
My testing scenario:
I have implemented a test application for iOS 5 , where I have one view with a UIWebView inside. This UiWebview is about to load the local index.html file as follows:
// Create an NSString from the local HTML file NSString *fullURL = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]; NSURL *url = [NSURL fileURLWithPath:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; // Load local HTML file [self.webView loadRequest:requestObj];
In this index.html file, I have a JS script that loads JSON from Flickr with the latest images uploaded to their shared channel. Each image is added to the list. This whole process is repeated every second until we reach 1000 images downloaded from the feed. See code:
var nImg = 0; function getData() { $.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?format=json&jsoncallback=?', function(data) { var items = []; $.each(data.items, function(i, image) { items.push('<li id="' + image.title + '"><img src="' + image.media.m + '"/></li>'); }); $('#page > #imagesList').append(items.join'')); nImg += items.length; }); $('#page > #numImages').html(nImg); if(nImg < 1000) setTimeout("getData();", 1000);
Finally, in my AppDelegate, I configured sharedURLCache as written in this post :
But, despite the fact that this should happen when I open the tools and run the application that checks the selection, the memory continues to grow when we upload images (up to 20 MB), instead of compressing about 4-6 MB, as I expected if UIWebView will use this sharedURLCache to cache downloaded images.

Does anyone know what I'm doing wrong? Am I misunderstood something? Am I loading the page incorrectly? Does UIWebView use a different cache for images uploaded to JS?
Please let me know your thoughts. I really need to understand how this sharedURLCache works, and how the UIWebView uses it to cache URLRequest, images ... if used at all. I do not want to have an application that uses a UIWebView that can allocate memory without control.