Android的位图释放内存 - 这一切都不工作 [英] Android Bitmap freeing memory - none of this works

查看:138
本文介绍了Android的位图释放内存 - 这一切都不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到位图大小超过VM预算,最终与我的应用程序。所以我加了所有这些事情,以帮助减轻日益增加的内存占用

I get "bitmap size exceeds VM budget", eventually with my app. So I added all of these things to help alleviate the increasing memory footprint

 BitmapFactory.Options options = new BitmapFactory.Options();

        options.inTempStorage = new byte[32*1024];
        options.inDither=false;                     //Disable Dithering mode

        options.inPurgeable=true;                   //Tell to gc that whether it needs free memory, the Bitmap can be cleared

        options.inInputShareable=true;              //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future


        options.inPreferredConfig = Bitmap.Config.RGB_565;

        Drawable pulled = BitmapDrawable.createFromResourceStream(null, null, conn.getInputStream(), "galleryImage", options);

我也使用weakhashmaps,回收的System.gc()

I am also using weakhashmaps, recycling, System.gc()

而这一切成功PROLONGES崩溃。其中,有32M堆的设备最初将只能够崩溃之前处理一些图片,现在可以处理一打,但这并不解决问题。这个问题是位图方法泄漏内存,而且根本不会清楚的。

and all this successfully PROLONGES the crash. where a device with a 32M heap initially would have only been able to handle a few images before crashing, now it can handle a dozen, but this doesn't fix the problem. The problem is the BitMap method is leaking memory and simply will not clear.

我该如何解决这个问题?这些图像大小256x357的

How do I fix this? The images are of size 256x357

推荐答案

您应该尝试使用 drawable.setCallback(NULL); 当你不需要绘制了,因为即使你使用的是WeakHashMap中,他们仍然可以通过其回调的属性附加到上下文。

You should try to use drawable.setCallback(null); when you don't need a drawable anymore, because even if you're using a WeakHashMap, they can still be attached to the context through their callback attribute.

请参阅

这篇关于Android的位图释放内存 - 这一切都不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆