ios - UIWebView 在加载 PDF 文件时没有释放内存
问题描述
我正在 UIWebView 中加载 pdf 文件(大小:15 MB)。
// If it is found, show it
[self.webView loadData:pdfData
MIMEType:@"application/pdf"
textEncodingName:@"UTF-8"
baseURL:nil];
问题是当我多次加载文件时,RAM 使用率会更高,并且应用程序在某个点崩溃。当我弹出视图控制器时,占用的内存没有释放。
解决方案
只需在您的代码中添加三行,然后检查
-(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];
}
推荐阅读
- c++ - Yolo 训练 API(暗网)
- autodesk-forge - 发送 api 活动请求时出现“未为帐户启用路由”错误
- reactjs - React HighCharts 自定义图例
- css - 如何隐藏 v-text-field 键入日期的图标
- c++ - 为 LeetCode 问题 Max Frequency Stack 获取未对齐地址错误的引用绑定
- kubernetes - Kubespray 和 Ansible,如何分离配置(即清单和其他配置文件)
- python - 在 matplotlib 散点图中添加过滤
- perl - 在@INC 中找不到 MIME/Types.pm
- apache-kafka - Apache Kafka 的 Spring 中的侦听器容器是什么?
- xcodebuild - xcdebuild ios14 与 googleMap 框架构建