In fact that's what Google does (or at least did at a certain point in
time), too.

When I meddled with a single MapActivity that could switch between
OpenStreetMap- and Google-Content, I constantly ran into OOMs. I found
out that internally the Google Maps-API had an OutOfMemoryHandler that
was triggered by OOMs from loading tiles (==> bitmaps). Whenever this
code ran I could observe a lot of heap getting freed (watching the
eventlog).
In the end I got the MapActivity running but needed to call the
OOMHandler reflectivly since it's not exposed in the API. I was never
satisfied with this solution, though, so eventually I switched to a "2
seperate activities, one delegate holding all the code"-approach.

What I want to say is: if Google does it, it's probably not bad
practice :)

Also, (maybe you already know this, but anyway) if you want to find
out what keeps your Objects from being GCed when you null your
objectreferences I can recommend MAT. It works on the hprof-heapdumps
you can get from the DDMS and has a feature called "Shortest way to
GC" (or something alike) where you select any object and find out
where it's being held.
You may be in for some surprises. Once I found out that some objects I
wanted to be discarded where still held by a Toast being displayed
earlier :-P

Ralf


On 11 Dez., 20:19, Matt Kanninen <mathias...@gmail.com> wrote:
> Can I ask what Android does with un caught OutOfMemoryErrors that it
> wouldn't do if I caught them?  It's really tempting for me to do this:
>
> try {
>             setContentView(R.layout.result);} catch (OutOfMemoryError E) {
>
>            outOfMemoryCount++;
>              e.printStackTrace();
>               finish();
>
> }
>
> If I don't catch the OutOfMemory my activity crashes, but then the
> user just clicks the button again and it loads great the second time.
> So something happens resulting in the right memory being cleared.

-- 
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