KeyEvent causing excessive garbage collect (GC)

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

KeyEvent causing excessive garbage collect (GC)

Postby snowcrash » Thu Jan 07, 2010 7:29 am

Tried posting on Google group... got nowhere so trying here...

I'm running into some issues with input events and garbage collection, or more precisely object allocation. I am creating a game and have pretty much got my head around the OpenGL environment. I've digested all the relevant material I could find regarding performance, memory allocation etc (and watched the excellent presentation by Chris Pruett - http://code.google.com/events/io/2009/s ... eGamesAn...).

I've pretty much eliminated any object allocations after initial setup from my game (which is still in its infancy), but I'm still getting a bunch of GC calls, like this:

DEBUG/dalvikvm(52): GC freed 10398 objects / 880928 bytes in 139ms

This is killing my frame-rate and creating a jittery experience, which is no good. Running DDMS I see that the culprit is MotionEvent and KeyEvent.

Allocations like:

656 float[] 3 android.view.MotionEvent <init>
656 float[] 3 android.view.MotionEvent <init>
656 float[] 3 android.view.MotionEvent <init>
656 float[] 3 android.view.MotionEvent <init>
656 float[] 3 android.view.MotionEvent <init>

(there are many more, this is just a snapshot)

It seems that every time a MotionEvent is recorded, a float array is created? I am just using the onKeyDown event in the main Activity to broker the key event to my game thread. I'm also sleeping (16ms) in this method call (as per Chris Pruett's recommendation) to save in excessive notifications.

Is there something special I can do to eliminate these allocations? Perhaps there is an alternate way of obtaining key events and or trackball events? (which also are a cause of several allocations)

Thanks in advance...
snowcrash
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jan 07, 2010 7:24 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests