I'm trying to test UIWebView's 10MB limit on Javascript memory allocation. Here is my code so far which I'm running 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 doesn't result in any exception being thrown by the UIWebView even though clearly the JS allocation at one point is greater than 10MB. I've used instruments to verify the memory usage.
The end result of the entire program is that I see bunch of 'c ' are printed on the screen in a webview but no crash.
Am I doing something wrong? How can I test this JS limit?
The limits vary by device. The Simulator does not impose the same limits as actual devices. If you test this on an iPhone, you should see an exception.