【问题标题】:UIWebView not freeing the memory on loading PDF filesUIWebView 在加载 PDF 文件时没有释放内存
【发布时间】:2018-12-04 20:08:53
【问题描述】:

我正在 UIWebView 中加载 pdf 文件(大小:15 MB)。

// If it is found, show it
[self.webView loadData:pdfData
              MIMEType:@"application/pdf"
      textEncodingName:@"UTF-8"
               baseURL:nil];

问题是当我多次加载文件时,RAM 使用率变高并且应用程序在某个点崩溃。当我弹出视图控制器时,占用的内存没有释放。

【问题讨论】:

  • 您可以单独添加答案,而不是编辑现有答案。
  • 那个答案给了我线索,所以我只修改了这个

标签: ios objective-c memory-management uiwebview


【解决方案1】:

只需在代码中添加三行,然后检查

-(void) dealloc
{
    [self.webview cleanForDealloc];
    self.webview = nil;
    [super dealloc];

}

更新:

当我移除视图控制器时调用下面的方法。

-(void)webViewUnload {

    [self.webView loadHTMLString:@"" baseURL:nil];
    [self.webView stopLoading];
    [self.webView setDelegate:nil];
    [self.webView removeFromSuperview];

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
}

【讨论】:

    猜你喜欢
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 2013-09-10
    相关资源
    最近更新 更多