Re: [android-developers] Avoiding garbage collection for smooth 2d animations
No matter what you'll see GC being called, there's no way around it (that I'm aware of).
There are background threads that are doing all sorts of things, which very well might be getting GC'd. Theres also a lot of things you can't reasonably avoid, like allocations from Iterators and such...
-- On Mon, Dec 28, 2009 at 12:32 PM, Mark Wyszomierski <markww@gmail.com> wrote:
Hi,
I'm drawing a rect to a surfaceview. Nothing special, just a test like
this, in the surfaceview-extended class:
private int mPosX = 0;
private Paint mPaint = new Paint();
@Override
public void onDraw(Canvas canvas) {
canvas.drawRect(mPosX-20, 50, mPosX+20, 70, mPaint);
mPosX += mSignX;
if (mPosX > 320) {
mSignX = -1;
}
else if (mPosX < 0) {
mSignX = 1;
}
}
the rect just bounces around the screen. I'm watching DDMS, I still
see the garbage collector being called, even with this simple draw
loop. There is no other application code being executed.
I'm wondering if it's realistic to expect the gc to not be called at
all if we take care to not allocate any objects during our draw loops.
I'm trying to extend this example to do some smooth animations, but
every once in awhile the gc is called and you can see the drawing
stutter. Although none of my application code is allocating any new
objects, I don't know what the underlying API is doing inside
surfaceview etc, and I doubt we can control that.
Just wondering if this is not possible, I'd prefer to abandon this
game idea up-front if we can't guarantee smooth animations,
Thanks
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home