UIWebView内存管理 [英] UIWebView memory management

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

问题描述

我的内存管理存在问题。

I have a problem with memory management.

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

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和许多webview(仪器说大约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时,整个视图将在内存中呈现。因此,除了用于加载图像和其他数据的内存(您在分配工具中看到的内容)之外,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 工具了解仪器中正在使用的内存量。

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天全站免登陆