Calling System.gc() is not guaranteed to run the GC at all (see the
documentation of
http://developer.android.com/reference/java/lang/System.html#gc()), let
alone reclaim all unused objects. Like I mentioned before, objects with a
finalizer, when collected, are enqueued in a reference queue which gets
processed by the finalizers thread. Depending on when this thread runs, and
when the GC runs, and how your chain of objects is constructed, it might
take a bit of time before a Bitmap (or other objects with finalizers) gets
truly cleared from memory. Again, this is not a leak since the Bitmap *will
be* freed; it just won't happen as early as you want. This is why, btw,
finalizers are often considered harmful and should be avoided as much as
possible.

As for Bitmaps that don't get reclaimed at all, that might be a true leak.
However, I don't recall such a leak occurring in recent versions of Android
(and I spend a lot of time tracking memory leaks and memory usage for each
release.) You might not know however that BitmapDrawables, when loaded from
the same resource, share a common single bitmap. This bitmap is kept in a
cache even after your drawables are collected, so that future creations of
these drawables will be much faster (this is a technique widely used
throughout the system to increase apps startup time.) If you don't want this
behavior, you should load the bitmap manually with BitmapFactory and create
a BitmapDrawable from that bitmap.

On Thu, Jan 13, 2011 at 1:09 AM, String <[email protected]>wrote:

> I respectfully disagree, though part of the issue could be terminology,
> what you consider a leak. I understand your explanation about the GC
> requiring multiple passes, but to my mind, if calling system.gc() doesn't
> reclaim unused memory, that's a leak. According to the docs, I shouldn't
> need to call it at all. Can you tell us how many calls are required to
> reclaim the memory from a no-longer-used bitmap?
>
> I am also certain that I've seen specific cases where the memory cannot be
> reclaimed at all - mostly involving BitmapDrawables - but I haven't had time
> to put together a minimal test case.
>
> Nonetheless, the news that this has been reworked for Gingerbread/Honeycomb
> is very good. :^)
>
> String
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them

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