TextureManager problem?

Started by Disastorm, July 20, 2011, 01:00:32 AM

Previous topic - Next topic

Disastorm

*edited this post a million times, texturemanager problem is last half of my post.

Hello I'm trying to figure out what to clear from memory on OnStop so that I don't have a memory leak.  Originally i had a big leak its because I wasn't disposing the framebuffer, but now it seems to be smaller.  Right now I am calling removeAndUnload on all the textures, world.dispose, and framebuffer.dispose.  Is there anything else I need to call?  Do i need to call some dispose method on the actual Object3Ds ( I didn't see one)? Also should I be using VBO?  Does that take any more memory than vertex arrays or does it not really matter?

*edit I think I mostly fixed my memory leak issue but maybe you can tell me if this sounds like there is one or not:

First Run after initialization of the world: 11800 KB (after calling MemoryHelper.compact)
second: 12450 KB
third: 12534 KB
fourth: 12547 KB



However, I just discovered another problem, on my fifth run, the TextureManager said I have too many textures despite the fact that I removeAndUnload them every time.  It said to change Config.maxTextures but in your javadoc it says "The manager wil increase the value if needed. This is in for historical reasons only. No need to adjust it. Default is 64. "  So is something weird happening?

*edit if only add the textures the initial time and do not add them after that, if i keep restarting my app, it eventually crashes with an out of memory error, something about converting the texture in the gl rendering or something.  Can you tell me what I should do about the texture problem because it is crashing my application.  I tried changing Config.maxTextures but that doesn't help. 

Also what does the "used out of" part mean in MemoryHelper.compact()'s log message?

*edit
oh wow i removed a 1MB texture and it freed up 8-9MB of memory? 

EgonOlsen

#1
So many questions...where should i start...well, the "too many textures"-thing is a porting error from desktop jPCT. I've ported the documentation but not the functionality. I'll fix this.

About removing and unloading and adding them again...actually, this shouldn't be needed at all. The TextureManager will keep track of texture usage. There's no need to remove and add them all the time. What might be needed is to unload them, because if not, old and new texture might exist both for one frame and if you are low on memory, this might cause problems. However, by default unloading happens in the next frame, which might not be what you want in this situation. You can set Config.unloadImmediately=true to avoid this, but make sure that you call the unload method in your render thread then.

Other options that you might want to consider are setting Texture.defaultTo4bpp(true) and calling compress() on each larger texture.

VBOs will increase memory usage a little bit, but it shouldn't really matter. If you are using the latest alpha (that one with ES 2.0 support), they are enabled by default anyway.

The message in MemoryHelper refers to the memory that the VM has reserved ATM.


Edit: Actually, there's no need to dispose the World either as long as you don't plan to reload everything from scratch. In AlienRunner, all i do is a FrameBuffer.freeMemory() and i never saw any memory leak.

Disastorm

#2
Thanks actually I just discovered the solution to the texturemanager was that i needed to unload it but keep the texture name in there.  And then instead of adding it back I call replace.  However, you mention that it keeps track of usage itself?  Do you mean I don't need to unload it to free memory?  I was thinking I would have a level and before the level I load all the textures for that level, then after i unload them and load textures for next level.  Is this a good idea?

Also, I think I got rid of the memory leak (not exactly sure how as I tried a bunch of different things including setting all my variables to null and also I think the change I did with unloading and replacing textures also helped).  I still see different values when starting up my level but they seem to bounce between 5MB-7MB range and then back to 5MB so it doesnt seem to be getting any higher.  Not sure why it changes though.  Well when the player exits the game I do plan on disposing the world and then reinitialize everything when they start the game again.  This sounds like the correct approach right?  Honestly, I don't like Android's style where they never actually end a process because it makes things very confusing.  I think I did try to call compress once on a texture but i got some error but I forgot what it was.  If I try that again I'll let you know.

*edit I just did compress and it seems to work for me now, also gives me more memory.  Is it good to just compress every texture?
Also where is this alpha version you mention, should I get that?  I'm just using the regular version from the download site.