Good news, gyus! I've found a way to get rid of garbage collection! The receipt is simple (and ironic): do not use allocateDirect(), use allocate(). And use only ByteBuffer, not FloatBuffer, IntBuffer, etc. - using asFloatBuffer() on non-direct ByteBuffer will result in crash in libhgl. (I'm too lazy to create an issue for that.)
E.g. this code: ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); vbb.order(ByteOrder.nativeOrder()); mVertexBuffer = vbb.asIntBuffer(); mVertexBuffer.put(vertices); mVertexBuffer.position(0); should be ByteBuffer vbb = ByteBuffer.allocate(vertices.length*4); vbb.order(ByteOrder.nativeOrder()); for (int vertex: vertices) { mVertexBuffer.putInt(vertex); } mVertexBuffer.position(0); and voila, no garbage collections on ADP 1.5 firmware. Please test and report your results here. Dmitry On 16 июл, 21:33, PaulT <dr.paul.thomas.android.st...@googlemail.com> wrote: > Hello everybody, > > I've created a simple OpenGL app and created a rendering class which > implements GLSurfaceView.Renderer. All it does is draw 100 triangles > (NUM_OBJECTS = 100) on the screen and move them about, bouncing off > the edges. The projection is glOrtho2D and there is no z-buffer. I'm > running this on a G1 with continuous redraw enabled. > > Here is the onDrawFrame method: > > public void onDrawFrame(GL10 gl) { > gl.glClear(GL10.GL_COLOR_BUFFER_BIT); > for (n = 0; n < NUM_OBJECTS; n++) { > gl.glPushMatrix(); > gl.glTranslatef(posX[n], posY[n], 0); > gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vBuffer); > gl.glDrawElements(GL10.GL_TRIANGLES, 3, GL10.GL_UNSIGNED_SHORT, > iBuffer); > gl.glPopMatrix(); > posX[n] += xa[n]; > posY[n] += ya[n]; > if (posX[n] > viewW || posX[n] < 0) { > xa[n] = -xa[n]; > } > if (posY[n] > viewH || posY[n] < 0) { > ya[n] = -ya[n]; > } > } > > } > > It's pretty simple stuff just to get an idea of the device > performance. Note that I am not leaking any garbage in this method. > > If we look at the logs while this is running, > > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 153ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 156ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 157ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 156ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 156ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 157ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 152ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 150ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 153ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 157ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 155ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 151ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 159ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 155ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 156ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 153ms > D/dalvikvm( 3085): GC freed 21842 objects / 524304 bytes in 158ms > D/dalvikvm( 3085): GC freed 21840 objects / 524256 bytes in 151ms > > Every few seconds, the garbage collector has a bit of a tidy up. If > we look at the frame rate, it is averaging out to be around 56Hz. I > speculate that the system can keep up with the 60Hz vertical sync just > fine until it needs to collect garbage. > > Nothing else is running so this stuff is definitely coming from this > app. Unfortunately it causes the display to pause briefly (160ms is > about 10 frames) so would not be acceptable in an interactive game. > Does anybody know what causes this (something in the OpenGL code?) and > can it be avoided? > > Thanks for any help. > > Paul. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---