【问题标题】:Recycle work good or not? in onDestroy()回收工作好不好?在 onDestroy()
【发布时间】:2017-11-04 20:28:50
【问题描述】:

我对在 imageview 中使用我的回收位图有疑问。

我使用此代码在 imageview 中回收图像。

drawable = imglist1.getDrawable();
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        Bitmap bitmap = bitmapDrawable.getBitmap();
        bitmap.recycle();
    }

我在 onDestroy 方法中调用它

@Override
    protected void onDestroy() {
    super.onDestroy();
         ...
    }

我在 imageviews 中有图像(位图) 打开新活动时(调用 onDestroy() )

打开新活动后在 android 监视器内存中看不到变化。

安卓显示器

如何控制回收是否有效,或者如何减少内存?

内存来自图像视图中的大部分位图。

感谢您的意见

【问题讨论】:

    标签: android memory bitmap recycle


    【解决方案1】:

    将位图标记为可回收后,只有在执行 GC 时才会释放。 这里有更多信息:Android: Bitmap recycle() how does it work?

    但是你的问题很不清楚。如果你在 onDestroy 中回收位图,这是没有意义的,因为在 onDestroy 中所有视图都将被释放,位图的引用也将被释放,因此它将在下一次执行时被 GC。

    对您来说最好的选择可能是重新采样您的图像。我发布的链接有更多信息。

    【讨论】:

    • 我想在打开其他活动时全部回收。
    猜你喜欢
    • 1970-01-01
    • 2012-12-27
    • 2010-09-17
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多