android webview 内存泄露
2015-03-06 16:57
127 查看
AndroidWebViewMemoryLeakWebView内存泄漏
在这次开发过程中,需要用到webview展示一些界面,但是加载的页面如果有很多图片就会发现内存占用暴涨,并且在退出该界面后,即使在包含该webview的Activity的destroy()方法中,使用webview.destroy();webview=null;对内存占回收用还是没有任何效果。有人说,一旦在你的xml布局中引用了webview甚至没有使用过,都会阻碍重新进入Application之后对内存的gc。包括使用MapView有时一会引发OOM,几经周折在网上看到各种解决办法,在这里跟大家分享一下。但是到目前为止还没有找到根本的解决办法,网上也有说是sdk的bug。但是不管怎么样,我们还是需要使用的。要使用WebView不造成内存泄漏,首先应该做的就是不能在xml中定义webview节点,而是在需要的时候动态生成。即:可以在使用WebView的地方放置一个LinearLayout类似ViewGroup的节点,然后在要使用WebView的时候,动态生成即:?2new | protectedonDestroy(){ .onDestroy(); mWebView.destroy()} |
24681012141618 | publicsetConfigCallback(WindowManagerwindowManager){ { class "mWebViewCore" field=field.getType().getDeclaredField( ); "sConfigCallback" field.setAccessible( ); null ( ==configCallback){ ; "mWindowManager" field.setAccessible( ); } (Exceptione){ | publiconCreate(BundlesavedInstanceState){ .onCreate(savedInstanceState);public onDestroy(){ null super <codeplain"=""style="margin:0px!important;padding:0px!important;word-break:break-all;font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace!important;border:0px!important;border-top-left-radius:0px!important;border-top-right-radius:0px!important;border-bottom-right-radius:0px!important;border-bottom-left-radius:0px!important;bottom:auto!important;float:none!important;height:auto!important;left:auto!important;line-height:1.1em!important;outline:0px!important;overflow:visible!important;position:static!important;right:auto!important;top:auto!important;vertical-align:baseline!important;width:auto!important;box-sizing:content-box!important;font-size:1em!important;min-height:inherit!important;background-image:none!important;background-position:initialinitial!important;background-repeat:initialinitial!important;">} |
---a/Source/WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp+++b/Source/WebKit/android/WebCoreSupport/UrlInterceptResponse.cpp@@-63,10+63,10@@public:JNIEnv*env=JSC::Bindings::getJNIEnv();//Initializeourreadbuffertothecapacityofout.if(!m_buffer){-m_buffer=env->NewByteArray(out->capacity());-m_buffer=(jbyteArray)env->NewGlobalRef(m_buffer);+ScopedLocalRef<jbyteArray>buffer_local(env,env->NewByteArray(out->capacity()));+m_buffer=static_cast<jbyteArray>(env->NewGlobalRef(buffer_local.get()));}intsize=(int)env->CallIntMethod(m_inputStream,m_read,m_buffer);if(checkException(env)||size<0)return;//Copyfromm_buffertoout.而且从这里
相关文章推荐
- Android webview 内存泄露的解决方法
- Android WebView 的内存泄露问题
- [Android] 关于WebView的内存泄露问题
- [Android] 关于WebView的内存泄露问题
- Android WebView 的内存泄露问题
- 关于WebView的内存泄露问题
- Andriod内存泄露之WebView
- WebView使用(内存泄露+获取网页标题+js交互+调用浏览器下载文件+网页加载失败+清缓存)
- webview 内存泄露解决办法
- 加载webView 内存泄露 导致内存暴涨的几种解决方案
- 关于WebView的内存泄露问题
- Android webView加载数据时内存溢出问题
- Android用WebView加载flash大文件偶然会出现内存溢出以及蓝色打问号小方块问题的解决方案
- android webView占用内存过大解决方案
- org.springframework.web.servlet.view.InternalResourceViewResolver 内存泄露问题
- android 内存泄露那些事情之View重用(三)
- 3.1.3 WebView 文件下载、缓存、内存泄露
- webView的内存泄露问题
- 加载webView 内存泄露 导致内存暴涨的几种解决方案
- Android使用多进程方式,解决Webview内存难释放的问题