????????最近發(fā)現(xiàn)項目中啟動頁的VideoView播放完即使調(diào)用stopPlayback()仍無法釋放內(nèi)存旁瘫。用MAT分析后知道它內(nèi)部的AudioManager對Activity進(jìn)行了強引用且生命周期超出了該Activity厌小,導(dǎo)致該Activity無法回收,解決方案如下:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(new ContextWrapper(newBase) {
@Override
public Object getSystemService(String name) {
// 解決 VideoView 中 AudioManager 造成的內(nèi)存泄漏
if (Context.AUDIO_SERVICE.equals(name)) {
return getApplicationContext().getSystemService(name);
}
return super.getSystemService(name);
}
});
}