开发者

Using UIWebView to render images instead of UIImageView in iOS uses much less memory. Makes sense?

I just figured out that - instead of using a UIImageView to show an image - I use an UIWebView, it uses much less memory. Does that make sense for anyone?

What I did was to get an ordinary .jpg 开发者_运维知识库file with about 280kb in size and show it on a simple app with just an UIImageView. Looking at Instrument's Object Allocations tool, the application's memory footprint was about 3MB.

Then I removed the UIImageView and added an UIWebView with the following code:

NSString *html = @"<html><body style='margin:0;'><img src='my_test_image.jpg'></body></html>";
[web loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

and then the memory usage dropped to around 700kb.

Any thoughts?


The UIWebView scale your image and crop it (When it is higher than the screen size...) It is an optimization from Apple in order to easily print every image on a website with less memory usage... The image quality change with the image size.

The UIImageView doesn't have that kind of optimization.


I don't think it will have such a major difference, even the oldest iPod Touch has 128MB of RAM. Just alloc and release it all correctly and you should be fine either way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜