VideoView 内存泄漏 [英] VideoView memory leak
本文介绍了VideoView 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你们有没有遇到过类似的内存泄漏?这就是我目前处理 VideoView 的方式
Has any of you encountered a similar memory leak? This is how I'm handling the VideoView at the moment
@Override
protected void onFinishInflate() {
super.onFinishInflate();
ButterKnife.bind(this);
Uri videoUri = Uri.parse(String.format("android.resource://%s/%s", getContext().getPackageName(), videoRes));
videoView.setVideoURI(videoUri);
videoView.setOnPreparedListener(mp -> {
mp.setLooping(true);
videoView.start();
});
}
这是我在 LeakCanary 上得到的
This is what I get on LeakCanary
感谢任何帮助!
推荐答案
ButterKnife 和 Fragments 一起使用时,需要使用 onDestroyView()
中的 Unbinder
来正确解引用片段的视图——因为片段与活动有不同的生命周期.
When using ButterKnife with Fragments, you need to use the Unbinder
in onDestroyView()
to correctly dereference the Fragment's Views -- since Fragments have different life cycles to Activities.
这篇关于VideoView 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文