How to check UIWebView 10MB restriction on JavaScript?

I am trying to check the 10MB UIWebView limit on Javascript memory allocation. Here is my code so far, which I run on the simulator (iOS 5.1).

int size = 10485760+1024000*10; int i = 13; char *cStr = (char *) malloc(size); // 20MB buffer char *lcStr = cStr; lcStr+=i; strcpy(cStr, "window._x = \'"); for ( ; i < size-4; i++){ if(i%2){ *lcStr = ' '; }else{ *lcStr = 'c'; } lcStr++; } strcpy(lcStr, "c\';\0"); NSString *longStr = [NSString stringWithCString:cStr encoding:NSASCIIStringEncoding]; // by now 40MB used //memory usage spikes to 60MB NSString *result = [self.webView stringByEvaluatingJavaScriptFromString: longStr]; free(cStr); 

HTML / JS:

 <script type="text/javascript"> setTimeout(function(){document.getElementById("one").innerText = window._x;},3000); </script> 

My problem is that the code above does not cause the UIWebView to throw any exception, although obviously the JS distribution at one point is more than 10 MB. I used tools to check memory usage.

The end result of the whole program is that I see that the heap "c" is printed on the screen in a web view, but without crashing.

Am I doing something wrong? How can I check this JS limit?

0
source share
1 answer

Limits vary by device. The simulator does not set the same limitations as the actual devices. If you check this on the iPhone, you will see an exception.

+1
source

All Articles