小编tel*_*tqq的帖子

如何在android中释放位图内存

在我们的程序中使用大量图像,我们在eyery Activity和Fragment中取消绑定,如下所示

protected void unbindDrawables(View view) {
    if (view != null) {
        if (view.getBackground() != null) {
            view.getBackground().setCallback(null);
        }
        if (view instanceof ImageView) {
            ImageView imageView = (ImageView) view;
            imageView.setImageDrawable(null);
        }
        if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                unbindDrawables(((ViewGroup) view).getChildAt(i));
            }
            if (!(view instanceof AbsSpinner) && !(view instanceof AbsListView)) {
                ((ViewGroup) view).removeAllViews();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

像这样/sf/answers/474534721/说,但我使用mat发现该位图也使用了大量内存而不是发布.

Class Name                               |   Objects | Shallow Heap | …
Run Code Online (Sandbox Code Playgroud)

memory android bitmap

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

bitmap ×1

memory ×1