问题描述
我从其他帖子中看到 UIWebView 存在内存泄漏问题.但是,由于我泄漏的对象数量众多,我不得不怀疑我是否做错了什么.'Leaks' 报告了关于打开 UIWebView、加载页面和关闭(它是 Facebook 登录页面)的 60 次泄漏.我已经检查了这些对象中的每一个的堆栈跟踪,它们从未接触过我的代码.它们要么都在一个单独的线程中(我只使用主线程),要么从主"转到一堆灰色的内部方法.这是 UIWebView 预期的吗?我正在运行最新的固件,我认为他们现在已经修复了这个问题.顺便说一句,我在设备上看到了这个.我也尝试在苹果网站上检查错误,但除了通过问题 ID 之外没有其他方法可以搜索..?
I've seen from other posts that there are memory leaking issues with UIWebView. However, with the amount of objects that I have leaking, I have to wonder if I'm doing something wrong. 'Leaks' reports about 60 leaks for opening a UIWebView, loading a page and closing (it's the Facebook login page). I've check the stack trace for every one of these objects, and they never touch my code. They're all either in a separate thread (I only use the main thread), or go from 'main' to a bunch of internal methods that are greyed out. Is this expected from UIWebView? I'm running the latest firmware, and I think they would have fixed this by now. I'm seeing this on the device, by the way. I also tried checking for bugs on the apple site, but there's no way to search other than by issue ID..?
肖恩
这是泄漏的捕获:
推荐答案
很抱歉这么快就回答了我自己的问题,但我刚刚发现了问题.
Sorry to answer my own question so quickly, but I just found the problem.
如果您为委托方法返回 NO:
If you return NO for the delegate method:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
然后释放 UIWebView,它会像上面描述的那样泄漏.返回 YES 可以解决问题.至少对我来说,到目前为止(4.3.3)的所有固件版本都会发生这种情况.我正在向 Apple 提交错误.
and then release the UIWebView, it will leak as described above. Returning YES fixes the issue. At least for me, this is happening on all firmware revisions up to now (4.3.3). I am filing a bug with Apple.
这篇关于(很多)UIWebView 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!