标签:存在 wrap rem images nexus save activity layout 解决
WebView mWebView = new WebView(getApplicationgContext());
LinearLayout mll = findViewById(R.id.xxx);
mll.addView(mWebView);
然后一定要在onDestroy()方法中显式的调用:
protected void onDestroy() {
super.onDestroy();
mWebView.removeAllViews();
mWebView.destroy()
}
注意: new WebView(getApplicationgContext()) ;必须传入ApplicationContext如果传入Activity的Context的话,对内存的引用会一直被保持着。有人用这个方法解决了当Activity被消除后依然保持引用的问题。但是你会发现,如果你需要在WebView中打开链接或者你打开的页面带有flash,获得你的WebView想弹出一个dialog,都会导致从ApplicationContext到ActivityContext的强制类型转换错误,从而导致你应用崩溃。
public class InnerClassActivity extends Activity{
private static Leak mLeak;
class Leak {
int a = 3;
private Context mLeakContext;
Leak(Context context) {
mLeakContext = context;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
mLeak = new Leak(this);
Toast.makeText(this, "This is InnerClassActivity", Toast.LENGTH_SHORT).show();
}
}
public class Singleton {
private static Singleton instance;
private Context mContext1;
private Singleton(Context context) {
this.mContext1 = context;
}
public static Singleton getInstance(Context context) {
if(instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton(context);
}
}
}
return instance;
}
}
public class WebViewCreateActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_create);
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
WebView webView = new WebView(this);
webView.setLayoutParams(layoutParams);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webView.loadUrl("https://www.baidu.com/");
ll.addView(webView);
Toast.makeText(this, "Hello", Toast.LENGTH_SHORT).show();
}
}
品牌 | 固件 | 泄漏点 |
---|---|---|
三星 | 4.0.4 | LightAppManager |
小米 | 5.0.1 | LightAppManager/ mAccessibilityManager |
华为 | 6.0 | LightAppManager/ mAccessibilityManager |
泄漏点2: WebView-wrapper getSystemService泄漏
It‘s 2016 now and, as far as I can see it, the issue still hasn‘t been resolved. I tested it on Nexus 5 and Nexus 6 with the latest WebView updates (since the component is now separate from the OS itself). Could someone, please, take a look at this issue?!
来源: https://code.google.com/p/android/issues/detail?id=9375
标签:存在 wrap rem images nexus save activity layout 解决
原文地址:http://www.cnblogs.com/linkun/p/6254479.html