gpt4 book ai didi

ios - UIWebView 在加载 PDF 文件时没有释放内存

转载 作者:行者123 更新时间:2023-11-28 23:56:43 29 4
gpt4 key购买 nike

I am loading the pdf file (sizes: 15 MB) in UIWebView.

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

问题是,当我多次加载文件时,RAM 使用率会升高,并且应用程序会在某个时刻崩溃。当我弹出 View Controller 时,占用的 ram 没有得到释放。

最佳答案

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

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

}

更新:

当我删除 View Controller 时调用下面的方法。

-(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];
}

关于ios - UIWebView 在加载 PDF 文件时没有释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51037201/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com