问题描述
我的项目是一个混合静态库,用于显示带有一些JS来控制逻辑的UIWebView.当我使用64bit并在iOS 8/iPhone 6上运行演示时,内存一直保持30M或更多!
My project is a hybrid static lib for showing a UIWebView with some JS to control the logic. When I use 64bit and run demo on iOS 8/iPhone 6, the memory keeps going to 30M or more!
-
当我在乐器中使用生成时,增加的内存使用量几乎全部来自webcore.这是否意味着JS代码泄漏?当我使用Safari直接运行类似的JS时,我找不到泄漏.
When I use generation in instrument, the increased memory usage is almost all from webcore; does it means there are leaks in JS code? I can't find a leak when I use Safari to run similar JS directly.
当我释放UIWebView时,内存仍然没有被释放.我测试了仪器配置.内存中还有一些Webcore和(非对象),我该怎么做才能释放它们?
When I release the UIWebView, the memory is still not freed; I tested with instrument allocation. There are some webcore and (non - object) still in memory, what can I do to release them?
- 0JavaScriptCore WTF :: MallocHook :: recordAllocation(void *,unsigned long)
- 1个JavaScriptCore WTF :: fastMalloc(unsigned long)
- 2 WebCore WebCore :: SharedBuffer :: buffer()const
- 3 WebCore WebCore :: SharedBuffer :: data()const
- 4 WebCore WebCore :: ResourceLoader :: didReceiveDataOrBuffer(char const *,unsigned int,WTF :: PassRefPtr,long long,WebCore :: DataPayloadType)
- 5 WebCore WebCore :: SubresourceLoader :: didReceiveDataOrBuffer(char const *,int,WTF :: PassRefPtr,long long,WebCore :: DataPayloadType)
- 6 WebCore WebCore :: SubresourceLoader :: didReceiveBuffer(WTF :: PassRefPtr,long long,WebCore :: DataPayloadType)
- 7 WebCore WebCore :: ResourceLoader :: didReceiveBuffer(WebCore :: ResourceHandle *,WTF :: PassRefPtr,int)
- 8 WebCore WebCore :: SynchronousResourceHandleCFURLConnectionDelegate :: didReceiveDataArray(__ CFArray const *)
我使用以下代码.
-(void)createUIWebview{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:serviceUrl]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}
-(void)dealloc{
if (_webView.isLoading){
[_webView stopLoading];
}
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
_webView.delegate=nil;
[_webView removeFromSuperview];
[_webView release];
_webView = nil;
}
我研究了以下链接,但它们似乎无法解决我的问题.UIWebview是否仍在iOS 8中泄漏?当我在iPhone4中使用iOS 6时,问题似乎并不明显.
I have researched the following links, but they don't seem to solve my problem.Is UIWebview still leaking in iOS 8? And the problem seems not so obvious when I use iOS 6 in iPhone4.
UIWebView泄漏,JS垃圾收集器和WebCore虚拟机
推荐答案
我遇到了同样的问题,并切换到新的WKWebView
,它立即解决了我所看到的所有内存泄漏问题. WKWebView
与UIWebView
共享许多相同的调用名称,因此我在项目上要做的就是将所有的'UIWebView'对象切换为'WKWebView',并且内存泄漏消失了.
I was having the same problem and switched to the new WKWebView
and it immediately solved all of the memory leak issues I was seeing. WKWebView
shares many of the same call names from UIWebView
so all I had to do on my project is switch over all my `UIWebView' objects to 'WKWebView' and the memory leaks went away.
请记住将WebKit
导入到您的项目中,并且知道仅在iOS8
上可用.
Remember to import the WebKit
into your project and know that is is only available on iOS8
.
这篇关于UIWebView的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!