On Jun 15, 10:36 pm, Romain Guy <[email protected]> wrote:
> >                                                Drawable s =
> > mCtx.getResources().getDrawable(R.drawable.symbol_icon);
> > Where s is a local variable to rendering. Suppose I call this 37
> > times.
> > Am I to assume that Android will do something smart like create only
> > one bitmap for this resource even if it is used 37 times?
>
> Drawables loaded from resources share as much data as possible. In
> this case, the 37 instances would use the same Bitmap data.

Romain, are there any circumstances under which this would not be
true?  I'm maintaining an app where a large number of
OutOfMemoryErrors are occuring in the field, all of them from the same
line of code which is a call to setBackgroundResource(R.id.a-local-
drawable).  The implication seems to be that repeat executions of this
line of code result in OutOfMemoryErrors.  The stack trace is:


    BitmapFactory.java-2):-1:in
`android.graphics.BitmapFactory.nativeDecodeAsset'
    BitmapFactory.java:464:in
`android.graphics.BitmapFactory.decodeStream'
    BitmapFactory.java:340:in
`android.graphics.BitmapFactory.decodeResourceStream'
    Drawable.java:697:in
`android.graphics.drawable.Drawable.createFromResourceStream'
    Resources.java:-1:in `android.content.res.Resources.loadDrawable'
    Resources.java:580:in `android.content.res.Resources.getDrawable'
    View.java:-1:in `android.view.View.setBackgroundResource'


One possible factor that might result in new memory usage is that the
drawable is resized to fit in to the view.  In its original form it's
a 9-patch containing a color gradient, with different dimensions from
the view it's loaded into.

Any thoughts about what might be consuming additional memory in these
calls, or how to prevent it?


thanks,
-Harry


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