android webview memory leak 線索

來源:互聯網
上載者:User

http://stackoverflow.com/questions/3130654/memory-leak-in-webview


I conclude from above comments and further tests, that the problem is a bug in the SDK: when creating a WebView via XML layout, the activity is passed as the context for the WebView, not the application context. When finishing the activity, the WebView still
keeps references to the activity, therefore the activity doesn't get removed from the memory. I filed a bug report for that , see the link in the comment above.

webView = new WebView(getApplicationContext());
share|edit answered Jun 28 '10 at 12:56

Mathias Lin
11.8k44284
 
1  
ty for that getApplicationContext() actually worked on my memory leak when creating the WebView. But when i add the webview to another
ViewGroup the memory Leak appears again. My wild guess is that adopts the parent's baseContext. Is there anyworkAround to that? I create the parent with getApplicationContext() too... so i guess i'm out of theories – weakwire Sep
20 '11 at 1:34
4  
Note that using the application context means that you won't be able to click on links in your webview, since doing so will result
in a crash: "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?" – emmby Jan
20 '12 at 23:47
  @emmby Thanks for the hint, wasn't thinking of that, as I just needed the webview to display more complex html (beyond what you can
do with a TextView), but no links in it. Therefore, I didn't come across the issue you mentioned, but thanks for pointing it out again. +1 – Mathias
Lin Jun
18 '12 at 15:27
2  
Also, any time the webview attempts to create a dialog (e.g., to remember a password, etc), the webview will crash as it expects an
activity context. – markshiz Aug
30 '12 at 18:13
1  
It crush app when webView want to display dialog for example asking "Do you want save passwaord" then it will crush  – Gelldur Dec
30 '12 at 20:52

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.