Well, you didn't post your code, so I can't be 100% sure, but my guess
is that there are other references to the same Drawables somewhere,
references that are NOT SoftReferences. That would keep it from being
garbage-collected.

Also, there is a difference between weak references and soft ones. It
you really want to make sure it is garbage-collected sooner rather
than later (it sounds like this is what you want), use a weak
reference not a soft one. A typical example of the difference is that
the Sun/Oracle JVM will clear all soft references before returning an
OOM.

That said, there is no requirement on the JVM that it actually treat
WeakReferences and SoftReferences differently. (http://
weblogs.java.net/blog/2006/05/04/understanding-weak-references).

Finally, there is actually a well known but in earlier versions (1.5,
1.6) of Android that is the opposite of what you describe: it reports
that SoftReferences are being GC'd too early instead of too late. See
http://stackoverflow.com/questions/4014033/android-the-gc-doesnt-respect-softreferences
for details.

On Apr 27, 11:24 am, dnkoutso <[email protected]> wrote:
> Hey everyone,
>
> I got an OOM. I know it has been covered alot by previous questions but mine
> has to do with the internals of Android.
>
> As I am loading images at random points I get this dreaded OOM exception.
>
> I do have my images in an HashMap>. From the SoftReferences definition I
> would expect the Drawables to be GC'ed if memory is not enough.
>
> In contrast, from my previous research I see that the bitmap in the drawable
> is allocated in a different heap (the native heap) than my applications
> heap. That explains why on DDMS despite the fact I see 6MB of memory I am
> using, my app still crashes.
>
> It also seems that SoftReferences are "perfect" for caches and are
> recommended by Android engineers to use.
>
> My question is, since my application heap never reaches the MAX point, this
> should mean my SoftReferences are never GC'ed.
>
> How can I resolve this problem? Is there really any gains from using
> SoftReferences then? Am I not understanding something correctly?
>
> Thanks!

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