java - ByteBuffer.wrap() in glTexImage2D causing excessive garbage collection -


 <: I make  

I am currently following an open call onDrawFrame () (an Android GLSurfaceView in) Code> GLES20.glActiveTexture (GLES20.GL_TEXTURE0); GLES20.glBindTexture (GLES20.GL_TEXTURE_2D, cameratext [0]); Gles20kglteksimage2D (Gles20kgl_tekscr_2D, 0, Gles20kgl_luminans, Kmpraviawsizekvidth, Kmpraviawsizekhait, 0, Gles20kgl_luminans, Gles20kgl_unsigned_bait, Bitebuferkwrap (Yarry)); GLES20.glTexParameterf (GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

I need to do this every frame (or something) because I use an Android camera with a custom callback method using the setPreviewCallback () live feed from the preview I am processing the camera inside / code> functionality, but my garbage collection is going completely wild (repeats about the following 10x one second!):

  .... GC_FOR_ALLOC 1530K, 42% free 3671K / 6307, 186 grams paused, GC_FOR_ALLOC Ukt 1530K, 42% Free 3671 that / 6307's, paused 22 MB GC_FOR_ALLOC free 1530K, 42% Free 3671's / 6307's, paused 25 MC GC_FOR_ALLOC free 1530K, 42% Free 3671's / 6307's, stopped the 20ms GC_FOR_ALLOC free 1530K, 42% free free free 3671K / 6307K, 20ms GC_FOR_ALLOC 1530K, paused, paused 42% free 3671K / 6307K 16ms GC_FOR_ALLOC freed 1530K, 42% free 3671K / 6307K, halted Is 22ms ....   

YArray is a byte array, and I wrap it in buffer. I have done using DDMS, and actually have the most alloted byte arrays, and by reading I have worked on the wrap function, it seems that it can make a [] to call an underlying byte, which then Once collected by the GC, it is used as a texture.

How can I reduce the number of allocations? Should I call GL in some way? It seems that I can reuse a single byte array instead, but I'm not sure how.

Any help would be appreciated! This amount of garbage scares me!

related to setPreviewCallback () method that causes excessive garbage collection using the solution new method is setPreviewCallbackWithBuffer where you re-added every fram with a buffer that is added and preallocate addCallbackBuffer method: < / P>

  Changed the surface of the public zeros (pagefolder holder, integer format, intestine w, int h) {... mCamera.addClallbackBuffer (callbackBuffer); MCamera.setPreviewCallbackWithBuffer (Cloud which implements preview callback); ...}   

Work buffer onPreviewFrame should be added again:

  [public void onPreviewFrame (byte] yuvArray, camera) {. ..camera.backback buffer (callback buffer); ...}   

To address initial suspicion that ByteBuffer.wrap () is allocating memory in GL call: it is not. This will actually use the built-in array (in the code provided in yArray ) and will not allocate new memory to collect garbage.

Comments