2

Everytime I load a html file that is larger than 2MB my app crashes. Is there a limit to how big a web page can be? How can I not crash my app (partial loading?)

Yazzmi
  • 1,541
  • 5
  • 18
  • 33

2 Answers2

9

When you load 2MB of HTML, the UIWebView has to consume a lot of memory to create a DOM and all of the controls/graphics/etc. to actually show the page. The limit is not the HTML size, but the resulting amount of memory that is needed to display it. Run it in the simulator with the Activity Monitor to see memory consumption

Xcode Instruments: peak RAM of iPhone apps running in Simulator?

You'll need to break down your pages or find another way to do the markup to make the memory smaller. Note that just making the HTML smaller might not help if you need to create the same page.

Community
  • 1
  • 1
Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • loading the page from the built-in Safari app seems to be ok. What's their trick? – Yazzmi Aug 09 '10 at 12:17
  • Then you have to make sure that aren't leaking memory in some other way. Do you literally have an app with just a UIWebView pointed at HTML and it crashes? Or are there other things going on that might have caused it. – Lou Franco Aug 09 '10 at 12:35
3

I bet you're ignoring the memory warnings that are being sent to your UIViewController subclass that is home to your UIWebView.

Uncomment -(void)didReceiveMemoryWarning and emit some NSLog messages from there. You'll probably see that the phone is frantically trying to get your attention about a low-memory condition. And when you don't respond by lowering memory use, it kills you.

What you want to do in that method is free any resources you're holding on to--images, big chunks of data, etc.

Dan Ray
  • 21,623
  • 6
  • 63
  • 87
  • How can I free resources within an UIWebView? – Yazzmi Aug 13 '10 at 07:33
  • Well that's a good question. Is that all your app is made of? There aren't other data structures you're navigating or images you're retaining? If not, I guess you let the UIWebView manage itself. It'll respond to low-memory events too. If anybody knows better, I'm interested to know the answer too. – Dan Ray Aug 13 '10 at 12:00