位图上可绘制优势,为内存在的android图上、优势、存在、android

2023-09-06 01:04:00 作者:炸掉ら奈何桥

这个问题是在以下问题的答案链接:

This question is linked with the answers in the following question:

Error去除位图[机器人]

有没有使用可绘制了位图在Android中的内存取消分配条款的任何优势?

Is there any advantage of using Drawable over Bitmap in Android in terms of memory de-allocation ?

我一直在寻找罗曼盖伊项目货架和他使用SoftReference的图像缓存,但我无法搜索哪里是code这是去分配这些可绘制时SoftReference自动回收的位图的内存。据我所知.recycle()必须明确呼吁它被解除分配的位图。

I was looking at Romain Guy project Shelves and he uses SoftReference for images caches but I'm unable to search where is the code which is de-allocating these Drawables when SoftReference automatically reclaims the memory for Bitmap. As far as I know .recycle() has to be explicitly called on the Bitmap for it to be de-allocated.

推荐答案

在我的理解,位图通常是性能更好,如果你不需要做太多的图像处理。不过,我遇到了内存泄漏时,我没有手动回收。我的解决办法是写一个类来帮助我管理图片它提供了一个简单的方法来回收所有我的位图在某些点在我的应用程序。它还提供了一种简单的方法来重复使用已经加载的资源(包括可绘制)。

In my understanding, Bitmaps are typically better for performance if you don't need to do much image manipulation. However, I have run into memory leaks when I don't manually recycle them. My solution was to write a class to help me manage my images that provides an easy way to recycle all my bitmaps at certain points in my application. It also provides an easy way to reuse already loaded resources (including Drawables).