我正在使用 Glide 加载位图来创建 gif。
for (int i = 0, count = files.size(); i < count; i++) {
Bitmap img = Glide.with(context)
.load(files.get(i))
.asBitmap()
.centerCrop()
.into(GIF_EXPORT_SIZE / 2, GIF_EXPORT_SIZE / 2)
.get();
// addFrame creates a copy of img, so we can re-use this bitmap
encoder.addFrame(img);
}
我想知道谁负责回收此 Bitmap 或将其放回 Glide BitmapPool 中? Glide 似乎没有办法自动或使用 clear()
重新使用它。
我考虑过使用 Glide.get(context).getBitmapPool().put(img)
之类的方法将 Bitmap 直接添加回池中,但根据文档,直接使用 BitmapPool 会导致到未定义的行为。
最佳答案
根据他们的 wiki,Resource re-use: How ,你不必回收,因为 Glide 会这样做,而是基于资源计数。
When the reference count drops to zero, Glide will recycle the resource and return its contents to any available pools.
尽管如此,您必须显式调用 Glide.clear() 来减少资源计数,因为 glide 只能在替换已存在的目标/ View 的图像时调用 Glide.clear() 。希望这会有所帮助。
关于android - 使用 Glide 加载位图时,谁负责回收它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31443503/