views:

277

answers:

2

Hi. I have an UIWebView that loads a embedded XHTML like this:

body = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
body.scalesPageToFit = YES;
body.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
body.autoresizingMask =  UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

[self.view addSubview:body];
[body loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"article16" ofType:@"xhtml"]isDirectory:NO]]];

This XHTML have a lot of images, and when I rotate the device I got some memory warnings, and sometimes the app crashes. If I remove the autoresizing mask, specifically the UIViewAutoresizingFlexibleWidth (I have tryed with only UIViewAutoresizingFlexibleLeftMargin and UIViewAutoresizingFlexibleRightMargin with no problems), the memory warning stops, and the app does not crash anymore.

If I remove all autoresizing mask, and set the new webView frame in didRotate or willRotate, I got the same warnings as using the UIViewAutoresizingFlexibleWidth.

There's a app, called Atomic Web that could open the same XHTML and rotate with no memory warnings, and safari can open it as well, but if I create a project with only that UIWebView, the app sometimes crashes.

Someone knows what this may be? Can I set the webview frame in other way? Why can't I use the autoresizing mask?

Thanks for your attention.

A: 

meet the same problem too!

A: 

I was seeing memory issues as well, but in a slightly different capacity with a UIScrollView. It appears that the [UIColor scrollViewTexturedBackgroundColor] property consumes a very significant amount of memory when your UIScrollView subclass, including UIWebView, applies it as the background color.

I would recommend changing it to just a plain color like gray. I noticed a 7 MB reduction in memory as reported by the activity monitor instrument by just making that simple change.

Heat Miser