Note that there are some explanatory texts on larger screens.

plurals
  1. POEnsuring OpenGL Texture Memory is Released
    text
    copied!<p>My application is running out of memory which switching between two activities. The first activity is running an OpenGL scene, the second activity is not. I want to make sure I am releasing all of the textures used by the OpenGL scene.</p> <p>Right now I am using this method</p> <pre><code>getNativeHeapAllocatedSize() </code></pre> <p>to track the relative amount of memory used by the textures. This number goes up by about 4 megs if I allocate textures. However it never seems to go back down again. </p> <p>In my first activities 'OnPause' I have the following code:</p> <pre><code>SurfaceView.onPause(); mTexture = null; </code></pre> <p>In the second activity I then call getNativeHeapAllocatedSize() several times. Even after the GC has run and the memory still has not dropped.</p> <p>Edit:</p> <p>After more research it appears it is something with the code that loads the data. I have removed OpenGL from the equation and the memory is still not being released.</p> <pre><code>try { InputStream is = null; { AssetManager am = MyActivity.getAssetMgr(); is = am.open( fileName ); } Bitmap b = BitmapFactory.decodeStream( is ); if( b != null ) { mResX = b.getWidth(); mResY = b.getHeight(); Bitmap.Config bc = b.getConfig(); if( bc == Bitmap.Config.ARGB_8888 ) mBPP = 4; else mBPP = 2; mImageData = ByteBuffer.allocateDirect( mResX * mResY * mBPP ); mImageData.order( ByteOrder.nativeOrder() ); b.copyPixelsToBuffer( mImageData ); mImageData.position( 0 ); return true; } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return false; } </code></pre> <p>Edit2:</p> <p>I did end up adding in all your ideas. However this seemed to be the problem in my case...</p> <p><a href="https://stackoverflow.com/questions/5060307/bytebuffer-not-releasing-memory/5305589#5305589">ByteBuffer not releasing memory</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload