VideoView内存泄漏 [英] VideoView memory leak

查看:206
本文介绍了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正确地取消引用Fragment的视图-因为Fragments具有不同的生命周期活动.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆