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.
Right now I am using this method
getNativeHeapAllocatedSize()
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.
In my first activities 'OnPause' I have the following code:
SurfaceView.onPause();
mTexture = null;
In the second activity I then call getNativeHeapAllocatedSize() several times. Even after the GC has run and the memory still has not dropped.
Edit:
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.
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;
}
Edit2:
I did end up adding in all your ideas. However this seemed to be the problem in my case...