Carefully study the exception type hierarchy. Error and Exception are distinct (and deliberately so). You are not catching OutOfMemoryError.
But catching an OutOfMemoryError and retrying is unlikely to succeed. The VM does GC before throwing the error. It's not entirely pointless, however -- occasionally a second GC will be able to collect something prior GC was not able to, possibly because of running finalizers or similar issues. Putting the call to System.gc() there isn't a requirement because of a deficiency in the VM, but rather a desperation move for when in desperate straits. It is quite likely that if that GC call helps, you're doomed to have another OutOfMemoryError soon, that you won't recover from. I'm NOT arguing against doing it, just putting it into context. It's survival mode programming. On Jun 8, 11:39 am, Greg Donald <[email protected]> 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 [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

