The code above does not make sure your bitmap will load.
If there is just no memory available, then the second loading of the
bitmap will fail as well and you'll still get the OOM exception.

Your code makes a best effort to load a bitmap.
This is because the raw binary data does count to the max limit of
heap-space for the process, but the DalvikVM does not 'see' it. It
just sees the Bitmap object, the wrapper around that raw binary data.
Calling System.gc() explicitly can mitigate that, since it does clean
up the raw binary data for the bitmap. However, when there's really
not enough memory, then an OOM is unavoidable.


On Jun 8, 2:39 pm, Greg Donald <gdon...@gmail.com> wrote:
> I used this sort of code to make sure my bitmaps load:
>
>     try
>     {
>       foo = BitmapFactory.decodeResource( resources, R.drawable.foo );
>     }
>     catch( Exception e )
>     {
>       System.gc();
>       foo = BitmapFactory.decodeResource( resources, R.drawable.foo );
>     }
>
> In 2.2, it's now failing sometimes and my catch block no longer
> catches anything.  Why would that be?
>
> Is there a better way to avoid a java.lang.OutOfMemoryError ?
>
> Thanks,
>
> --
> Greg Donald
> destiney.com | gregdonald.com

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

Reply via email to