Creating a new Paint object is mentioned as something to avoid here:
http://android-developers.blogspot.com/2009/02/track-memory-allocations.html

I suppose it really depends on the frequency of the onDraw calls. I
can tell you that it made a noticeable difference for us. We have a
custom view that you can fling, and when we stopped allocating Paint
objects the scrolling became noticeably smoother -- it didn't have
those annoying little hickups anymore.

In general, I prefer having zero calls to new in painting code. This
includes String concatenation, the most insidious form of object
allocation in Java. =)

On Apr 4, 10:54 am, Ikon <ayanafr...@gmail.com> wrote:
> Does that really help? I mean, is GC that bad?
>
> On Apr 4, 4:03 am, Greg Krimer <gkri...@gmail.com> wrote:
>
> > That sounds fine to me. Just remember to respect the clip rectangle
> > (canvas.getClipBounds()) and ideally not spend time computing Paints
> > for areas outside the clip.
>
> > Also, don't create a new Paint object in onDraw(). Create the Paint
> > object once, store it in your view and re-use it on every draw
> > operation.
>
> > On Apr 3, 11:03 am, Bob <bshumsk...@yahoo.com> wrote:
>
> > > > If it's drawing logic, then it's fine :)
>
> > > There is a lot of logic in varying the Paints though.
>
> > > On Apr 3, 12:49 pm, Romain Guy <romain...@google.com> wrote:
>
> > > > If it's drawing logic, then it's fine :)
>
> > > > On Fri, Apr 3, 2009 at 10:48 AM, Bob <bshumsk...@yahoo.com> wrote:
>
> > > > >> onDraw() should normally not contain any logic code.
>
> > > > > All the logic I have is necessary to draw my canvas.  It looks to me
> > > > > like that is going on in onDraw in the APIdemos, for example in
> > > > > Layers.java.  Am I mistaken here?
>
> > > > > Should I be drawing into a bitmap or something when one of my inputs
> > > > > changes and then using onDraw to read from that bitmap or something so
> > > > > as not to repeatedly do the same thing?
>
> > > > > Thanks,
> > > > > Bob
>
> > > > --
> > > > Romain Guy
> > > > Android framework engineer
> > > > romain...@android.com
>
> > > > 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 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