UIWebView 内存管理 [英] UIWebView memory management

查看:18
本文介绍了UIWebView 内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的内存管理有问题.

我正在开发一个大量使用 UIWebView 的应用程序.这个应用程序在从我的服务器加载内容时动态生成大量 UIWebViews.其中一些 UIWebViews 非常大并且有很多图片.

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.

如果我使用仪器检测泄漏,我不会检测到任何泄漏.但是,分配了很多对象,我怀疑这与 UIWebViews 相关.

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.

当webviews因为不再需要而释放时,似乎并不是所有的内存都被释放了.我的意思是,在向我的服务器发出请求后,该应用程序会创建一个 UITableView 和许多网络视图(仪器说大约 8Mb).当用户回按时,所有这些都被释放,但内存使用量仅减少约 2-3 Mb,并且在使用该应用 5-10 分钟后崩溃.

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?

谢谢!

推荐答案

这不是解决方案,而是对您所面临问题的可能解释.

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

我使用的应用程序出现内存问题.它由(实际上)一个滚动视图组成,包含 3 个全屏大小的 Web 视图.每个 webview 的内容大小是多个屏幕,平均说 10 个.

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.

当你加载一个 webview 时,整个视图都在内存中呈现.因此,除了用于加载图像和其他数据(您在 Allocations 工具中看到的内容)的内存之外,Web 视图本身在呈现时会使用内存,而您无法控制.

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.

因此,例如,一个 768x1024 的 webview,有 10 页的内容将使用

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

768 * 1024 * 10(页)* 4(每像素位数)= 31,457,280 = 30MB.

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

乘以 3 个网页浏览量,即 90MB 用于应用直接分配的内存.

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

您可以使用 VM Tracker 工具了解 Instruments 中像这样使用了多少内存.

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

这篇关于UIWebView 内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆