Turns out I was right.
My benchmark app is ready. As usual, I've made the entire project available. It's available at
https://dl.dropboxusercontent.com/u/81986513/122013/WebPageMemoryTester.zip and can be used for your benchmarks too.
I've made it VERY simple it doesn't even have XIB's. The view controller,
WebPageMemoryTesterViewController, (programmatically) creates an instance of UIWebView with the size of the full screen (minus the upper status bar, of course) and adds it as a subview to the current view. Then, it starts loading nin.com and starts a timer (
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector😡selector(print_free_memory) userInfo:nil repeats:YES]😉, which, by calling print_free_memory (based on
http://stackoverflow.com/questions/5012886/knowing-available-ram-on-an-ios-device ) displays not only the free /used memory, but also their difference between the first and previous value of the current free memory and the original / previous one (this is what the
origFreeMem and
prevFreeMem globals are for. The third global,
int seccounter;, makes it simply easier to spot time differerences as I've opted for using printf()'s instead of NSLog()'s to hide the usual NSLog prefixes).
I also directly call print_free_memory from not only the timer, but also immediately before and after creating UIWebView and immediately starting to load the web page into it. Also, I directly call it from the didReceiveMemoryWarning method so that we can see how much free memory the system had upon the warning.
I've run the tests on several of my devices, with various iOS versions and screen resolutions. I've reset every device before the tests so that they can have as much free RAM as possible. Three of the devices are JB'n but this fact didn't really have any effect on the results. After all, the free RAM of my non-JB'n 7.0.4 iPad 3 was 659349504, while that of my 6.1.2-based, JB'n iPad 3 was 625999872 that is, some 35 Mbytes only.
The results certainly show what I talked about:
- UIWebView consumes a LOT of memory. Retina iPad 3's with 1 GB memory simply can't even load it because the page just won't fit into the memory, regardless of the OS version.
- the higher the screen resolution, the significantly(!) more memory used. This is certainly visible if you compare the iPad2 figures to those of the two iPad 3's. The non-retina iPad 2 allocates significantly less memory when loading / scrolling around the page and, if you don't scroll too quickly, you can actually have a chance to be able to read it entirely.
- the number of pixels of the 640*1136 iPhone 5 is around the same (727k) as that of the 1024*768 iPad 2 (786k). Still, the former consumes almost two times more memory to load / render the same webpage (I would have expected the iPad 2 to consume somewhat more memory because of the higher-res screen). Dunno if this is caused by the iPhone 5 running 7.0.4 and the iPad 2 only 6.1.2.
Links to logs + more thorough explanation:
The 5.1.1-based, JB'n iPhone 3GS couldn't even load the page. As you can check out in the full log at , in second 42, immediately before didReceiveMemoryWarning being invoked, we only had 3.5Mbytes (3555328) of free RAM, while the Web page has already been allocated 104Mbytes (104001536):
84; DIFF ORIG: 104001536; DIFF PREV: 471040
used: 73666560 free: 3555328 total: 77221888
The 4.3.3-based, non-JB'n iPod touch 4 crashed at loading too (after allocating 85M (85803008) bytes; full log:
https://dl.dropboxusercontent.com/u/81986513/122013/14UIwebView/ipt4g.txt ):
didReceiveMemoryWarning; 100; DIFF ORIG: 85803008; DIFF PREV: -647168
used: 60604416 free: 2506752 total: 63111168
The 7.0.4-based, non-JB'n iPhone 5 started with 626Mbytes of free RAM (626913280; full log:
https://dl.dropboxusercontent.com/u/81986513/122013/14UIwebView/ip5.txt ). It has finished loading the entire page at around the 55th second (around tick 110), allocating 335 Mbytes (335597568) in the process:
111; DIFF ORIG: 335597568; DIFF PREV: 0
used: 378970112 free: 291315712 total: 670285824
Then, I started to (quite slowly fast scrolling would have crashed the widget) scroll down. During this, I've encountered several didReceiveMemoryWarning invocations. Then, the free RAM was around 70 Mbytes (70344704; a considerable drop from the 291M free after loading the page) and the widget allocated itself around 556 Mbytes (556568576):
129; DIFF ORIG: 556568576; DIFF PREV: 131567616
used: 577814528 free: 70344704 total: 648159232
After getting to the bottom and waiting a bit for everything possible to be released, I regained most of my, during the scrolling, missing free memory, which was around 274M (274776064); that is, not much less than the starting 291M:
145; DIFF ORIG: 352137216; DIFF PREV: -8192
used: 432508928 free: 274776064 total: 707284992
Then, a quick scroll to the top (by tapping the status bar) could have easily crashed the app as it, at the worst half-second, resulted in only 38Mbytes (38494208) remaining free:
153; DIFF ORIG: 588419072; DIFF PREV: 13512704
used: 527482880 free: 38494208 total: 565977088
The 7.0.4-based, non-JB'n iPad 3 couldn't load the page either (full log:
https://dl.dropboxusercontent.com/u/81986513/122013/14UIwebView/ipad3.txt ). Very soon after UIWebView had allocated around 650 Mbytes (648257536) and there remained only 11Mbytes of RAM (11091968), it crashed:
didReceiveMemoryWarning; 31; DIFF ORIG: 648257536; DIFF PREV: 79646720
used: 468738048 free: 11091968 total: 479830016
The 6.1.2-based, JB'n iPad 3, starting with a free memory of around 625 Mbytes (625999872), received its first didReceiveMemoryWarning callback at around 80 Mbytes of free (80945152) and, then, after half a second later, crashed at 8MB free (8798208), with the Web widget having allocated 617Mbyte (617201664) (full log:
https://dl.dropboxusercontent.com/u/81986513/122013/14UIwebView/ipad3-612.txt ):
didReceiveMemoryWarning; 25; DIFF ORIG: 545054720; DIFF PREV: 22192128
used: 465739776 free: 80945152 total: 546684928
26; DIFF ORIG: 617201664; DIFF PREV: 72146944
used: 517550080 free: 8798208 total: 526348288
The 6.1.2-based, JB'n iPad 2 only allocated around 200 Mbytes (201277440) of RAM to load the entire page with just a little bit (10Mbytes) of free RAM (10838016); see for example (full log:
https://dl.dropboxusercontent.com/u/81986513/122013/14UIwebView/ipad2.txt )
177; DIFF ORIG: 201277440; DIFF PREV: 0
used: 165519360 free: 10838016 total: 176357376
I started (slowly) scrolling down at tick 177; apart from occasional didReceiveMemoryWarning invocations, this could be done without crashing. So could I tap the upper status bar to quickly return to the top.
----------
(Just a quick note: see my benchmarks above.)