jPCT-AE - a 3d engine for Android > Support
Memory usage growing
robert:
Hi there,
In my wallpaper, the user can choose what mesh (Object3D loaded from .obj) to use in the preferences, and what skybox textures to use for the background. I'm changing both things in onSurfaceChanged() and it seems the memory usage grows up every time the wallpaper is restarted (with an orientation change for example).
I'm calling the dispose() method of the Framebuffer, World, and SkyBox (don't know if other classes also have this method) classes when the surface is destroyed. Also, when I replaceTexture() I previously call unloadTexture(), but all theses things don't keep the memory usage from growing. I've even tried to call the flush() method of the TextureManager class when the surface is destroyed, but again, the memory usage keeps growing. Forcing the garbage collector to run doesn't free up any memory, so I think the memory is referenced somewhere, but not in my code, because I null all the references onSurfaceDestroyed()....
What else should I do ?
Thank you!
EgonOlsen:
How are you loading your textures? If you load them as Bitmap or Drawable, Android will cache them. Does this increasing memory consumption reaches a limit or does it increase until you get an OutOfMemoryError?
You might want to profile you app (if it's actually possible to profile a wallpaper properly with the means that Eclipse and the Android plugin provide...) to see where the memory goes. Personally, i'm not aware of any existing memory leaks in the engine.
robert:
--- Quote from: EgonOlsen on October 02, 2012, 08:33:13 pm ---How are you loading your textures? If you load them as Bitmap or Drawable, Android will cache them. Does this increasing memory consumption reaches a limit or does it increase until you get an OutOfMemoryError?
You might want to profile you app (if it's actually possible to profile a wallpaper properly with the means that Eclipse and the Android plugin provide...) to see where the memory goes. Personally, i'm not aware of any existing memory leaks in the engine.
--- End quote ---
Hi Egon,
I'm loading the textures like this:
--- Code: ---TextureManager tm = TextureManager.getInstance();
String name = "light_" + mLightTex;
int id = res.getIdentifier(name, "drawable", mContext.getPackageName());
if (tm.containsTexture("light")) {
tm.unloadTexture(mFrameBuffer, tm.getTexture("light"));
tm.replaceTexture("light", new Texture(res.getDrawable(id), true));
} else {
tm.addTexture("light", new Texture(res.getDrawable(id), true));
}
--- End code ---
And this is what I do to release resources onSurfaceDestroyed():
--- Code: ---
if (mFrameBuffer != null) {
mFrameBuffer.dispose();
mFrameBuffer = null;
}
if (mSkyBox != null) {
mSkyBox.dispose();
mSkyBox = null;
}
if (mWorld != null) {
mWorld.dispose();
mWorld = null;
}
TextureManager.getInstance().flush();
--- End code ---
It seems the memory consumption keeps increasing, but does not make the program crash. The problem is that the text on the PreferenceActivity of my Wallpaper gets corrupted after a while.
EgonOlsen:
Try to load the textures via an InputStream (for example: res.openRawResource(R.raw.texture)) instead and see if that helps.
What's the relation between memory usage and the text on the Activity?
robert:
--- Quote from: EgonOlsen on October 03, 2012, 12:10:23 am ---Try to load the textures via an InputStream (for example: res.openRawResource(R.raw.texture)) instead and see if that helps.
What's the relation between memory usage and the text on the Activity?
--- End quote ---
Unfotunately, it makes no difference if I load the textures via an Inputstream :(
Here (http://tinypic.com/r/28m2452/6) you have a short video (01:30) that shows the increase in memory usage. Everytime you see the data changes is because I've rotated the phone... Also, you can see that in the end, when the memory usage reaches 27MB it goes back down to 17/18MB...
I don't know what the relation is between the missing text in PreferenceActivity and the memory usage, maybe it has nothing to do, but the text corruption always happens after a few orientation changes, never at the beginning...
Also, I would like to know if it is really necessary to call dispose() on the World and SkyBox objects (I know you call it on the Framebuffer).
Thank you!
Navigation
[0] Message Index
[#] Next page
Go to full version