且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

毕加索的内存不足错误

更新时间:2022-06-27 00:08:27

相似的问题. Android Picasso ImageView-内存不足异常MemoryLeak

Android解包"您的图片(即将其解码为位图)时,每个像素将使用4个字节.计算像素的数量,将其乘以4,然后乘以20(图像的数量),您可能会接近100mb的数字.例如,如果您的图像分辨率为1,000,000像素,则为1,000,000 x 4 x 20 = 80mb.

When Android "unwraps" your image (i.e. decodes it to bitmap), it will use 4 bytes per pixel. Count the number of pixels, multiply that by 4 and then by 20 (number of your images) and you'll probably get close to the 100mb figure. For instance, if your images have 1,000,000 pixel resolution, it would be 1,000,000 x 4 x 20 = 80mb.

使用某种LRU缓存或类似的缓存(或使用可为您处理缓存的Universal Image Loader库),仅在需要时加载位图.

Use some kind of LRU cache or similar (or alternatively use Universal Image Loader library which handles caching for you) and only load your bitmaps when you need them.