My apologies to anyone who had spent a significant amount of time
looking into this. The inPurgeable option does indeed work for bitmaps
read in using the BitmapFactory.decodeFile method.

The problem I was having was down to the fact that any bitmap that is
used to back a canvas cannot be recycled unless you make the canvas
equal to null first.

Canvas mCanvas;
Bitmap mBitmap;
private example()
{
    mBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
    ...
    //draw something to the canvas
    ...
    mBitmap.recycle(); //THIS DOESN'T WORK
}

Doing this will not recover the memory used by mBitmap, unless you do
mCanvas = null before it.

Is this a bug???

On 17 Apr, 00:01, Nilz <[email protected]> wrote:
> Hi,
>
> Can anyone explain why when I load images from files using
> BitmapFactory.decodeFile and passing in a BitmapFactory.Options 
> withinPurgeableset to true, I still get OutOfMemoryError?
>
> For example, doing the following many times, with lots of different
> resources works fine:
>
> BitmapFactory.Options opts = new Options()
> opts.inPurgeable= true;
> bitmap = BitmapFactory.decodeResource(resources, resId, opts);
>
> However, doing the following causes an OutOfMemoryError
>
> BitmapFactory.Options opts = new Options()
> opts.inPurgeable= true;
> bitmap = BitmapFactory.decodeFile(myFile, opts);
>
> In reality my code isn't as simple as outlined above. What I'm really
> trying to do is load a couple of bitmap resources draw them on a
> bitmap backed canvas, and then write this new bitmap to file, just so
> it can then be finally re-read into memory with theinPurgeableoption
> set to true (using BitmapFactory.decodeFile).
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to