Okay so I am making a live wallpaper for android phone but up until now, I have never noticed this issue.
Basically I am looking to see if my texture load & unload function is efficient or at least not horrible.
Breakdown of what happens on run:
-Wallpaper initialized.
-Texture manager Loops through all textures and loads them using glBindTexture.
-Wallpaper shows up running perfectly fine. Using 21mb of ram.
-I have the background flip back and forth every few seconds, both backgrounds are already loaded.
-I change background by doing this ---> paramGL10.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.textures[i]); ( I flip/ flop the integer between 0 and 1 for instance )
-On phone lock unload textures
-On phone resume, reload textures.
My ram increasing slowly but steadily. I don't understand why, all of my openGL knowledge has been self taught trial and error so I probably am not using the most efficient way of doing this.
Increases continuously I have seen it go as high as 81mb.
Here is my code.
Texture Manager Loading Textures on initial run, or after phone was resumed.
Code :public static void loadTextures(GL10 paramGL10) { paramGL10.glGenTextures(MAX_TEXTURES,textures,0); bindTextureIDs(paramGL10, "blank"); bindTextureIDs(paramGL10, "grid"); etc etc etc
Code :public static void bindTextureIDs(GL10 paramGL10, String fileName) { int ID = textureIDs.size(); textureIDs.put(fileName, ID); try { int resID = context.getResources().getIdentifier(fileName, "drawable", ApplicationPackageName); BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_4444; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resID, bitmapOptions); paramGL10.glBindTexture(GL_TEXTURE_2D,textures[ID]); paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST ); paramGL10.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); paramGL10.glTexParameterf(GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); paramGL10.glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); GLUtils.texImage2D(GL_TEXTURE_2D,0,bitmap,0); paramGL10.glFlush(); bitmap.recycle(); } catch(Exception e) { Log.v("TEST","Texture Data Corrupt, Re-download Package."); } }
Texture Manager unloading textures on lock.
Code :public static boolean unload(GL10 paramGL10) { try { Log.v("TEST", "TextureManager Unloading Textures"); paramGL10.glDeleteTextures(MAX_TEXTURES, textures, 0); paramGL10.glFlush(); TextureManager.textureIDs.clear(); isLoaded = false; } catch (Exception e) {} return true; }
And my rendering code
Code :public void render(GL10 paramGL10, TextureManager paramTextureManager, MeshManager paramMeshManager) { int i = paramTextureManager.getTextureID(paramGL10, this.texName); Mesh localMesh = paramMeshManager.getMeshByName(paramGL10, this.meshName); paramGL10.glPushMatrix(); paramGL10.glTranslatef(this.origin.x,this.origin.y, this.origin.z); paramGL10.glRotatef(180,0,0,1); paramGL10.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.textures[i]); if (this.color != null) paramGL10.glColor4f(this.color.x, this.color.y, this.color.z, this.color.a); paramGL10.glScalef(this.scale.x, this.scale.y,this.scale.z); paramGL10.glRotatef(this.angles.a, this.angles.x, this.angles.y, this.angles.z); localMesh.renderFrame(paramGL10); paramGL10.glPopMatrix(); }
Can anyone help me explain why this is leaking my memory, I figured if I locked my phone and unlocked it after the memory leaked a lot, the unload and reload should clear the GPU memory but it does not.
I hope someone is able to help me see the error of my ways!
Thanks



Reply With Quote