views:

112

answers:

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?)

+3  A: 

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
How can I free resources within an UIWebView?
Yazzmi
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
+4  A: 

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

http://stackoverflow.com/questions/2153271/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.

Lou Franco
loading the page from the built-in Safari app seems to be ok. What's their trick?
Yazzmi
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