Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

iphone - UIWebView memory management

I have a problem with memory management.

I am developing an application that makes heavy use of UIWebView. This app generates dynamically lots of UIWebViews while loading content from my server. Some of these UIWebViews are quite large and have a lot of pictures.

If I use instruments to detect leaks, I do not detect any. However, lots of objects are allocated and I suspect that has to do with the UIWebViews.

When the webviews release because no longer needed, it appears that not all memory is released. I mean, after a request to my server the app creates an UITableView and many webviews (instruments say about 8Mb). When user tap back, all of them are released but memory usage only decrements about 2-3 Mb, and after 5-10 minutes using the app it crashes.

Am I missing something? Anyone know what could be happening?

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This isn't a solution, but a possible explanation of the issues you're facing.

I had memory problems with an app I worked on. It consisted of (in effect) a scroll view, containing 3 full screen sized web views. Each webview's content size was multiple screens, say 10 on average.

When you load a webview, the whole view is rendered in memory. SO, aside from the memory used to load the images and other data (the stuff you see in the Allocations instrument), the web view itself uses memory when it's rendered that you have no control over.

So, for example, a 768x1024 webview, with 10 pages of content would use

768 * 1024 * 10 (pages) * 4 (bits per pixel) = 31,457,280 = 30MB.

Multiply by 3 web views, and that's 90MB used on top of memory that the app allocated directly.

You can get a feel for how much memory is being used like this in Instruments, using the VM Tracker instrument.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...