回收工作好不好?在 onDestroy() 中

Recycle work good or not? in onDestroy()

我对在 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 中有图像(位图) 当打开新的 activity (调用 onDestroy() )

打开新的 activity 后无法在 android 监控内存中看到更改。

android 班长

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

记忆它来自图像视图中的大部分位图。

谢谢你的想法

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

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

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