【问题标题】:Why UIWebView Eating so many Memory?为什么 UIWebView 会吃掉这么多内存?
【发布时间】:2011-05-04 00:40:13
【问题描述】:

我正在使用 UIWebView 为我的 iPad 应用加载纯文本 HTML 页面。 HTMP 页面的大小只有 40KB。但是当我使用仪器监控加载UIWebView的内存使用时,我发现它消耗了大约20MB的内存,如果我滚动网页视图,内存甚至越来越高。最后我收到了 1 级内存警告。

谁能帮我解决这个问题?我怎样才能减少内存呢? (我需要使用 HTML 在这里显示文本)。

 NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"SPC"];
 NSURL *url = [NSURL fileURLWithPath:htmlPath];
 NSURLRequest *request = [NSURLRequest requestWithURL:url];
 [webView loadRequest:request];

【问题讨论】:

  • html 页面是否以某种方式导入其他文件(html、样式表、脚本)?
  • 一个空的 webview 消耗多少内存?
  • 我也有同样的问题,你找到解决办法了吗?

标签: iphone objective-c cocoa-touch memory uiwebview


【解决方案1】:

html路径 网址 请求

在这一行之后全部释放

[webView loadRequest:request];

然后在 dealloc 中释放 webview 并使用 webview 作为 ivar

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 2018-10-10
    相关资源
    最近更新 更多