Author Topic: FrameBuffer.freememory sometimes useless?  (Read 2777 times)

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
FrameBuffer.freememory sometimes useless?
« on: April 27, 2015, 11:04:34 am »
Solved by ego
Answer:GLSurfaceView.setPreserveEGLContextOnPause(true);

_______________________________________________________
without touch phone's home button,freememory method it was good.
it free memory immediately,very nice.
but if i touch phone's home button and return to my app again.
the freememory method was never work,and the memory was never free.


may be my bug was in onSurfaceChanged?

here is my code:

public void onSurfaceChanged(GL10 gl, int width, int height)
{       
  fb=null;
  fb=new frameeBuffer(width,height);
  Config.unloadImmediately=true;                   
  texturemanage.removeAndUnload("a", fb);      
  texturemanage.removeAndUnload("c", fb);
   ................................................
  fb.freememory;
 }


« Last Edit: April 29, 2015, 04:48:55 am by Uncle Ray »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: FrameBuffer.freememory sometimes useless?
« Reply #1 on: April 27, 2015, 09:00:54 pm »
freeMemory() basically unloads all known textures (to the TextureManager) from native memory. This should actually happen if the context get's destroyed anyway, so it might not be very useful. You can monitor what it does if you set the Logger to debug mode. That should give you some log outputs like "Unloaded texture: <int>".

Anyway, what's the point of doing this in onPause and how do you judge that it doesn't do anything?

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: FrameBuffer.freememory sometimes useless?
« Reply #2 on: April 28, 2015, 11:46:30 am »
because,if i without  touch home button,like "Unloaded texture: <int>",will display.

but,if i touch home button and return my app,like "Unloaded texture: <int>".was disappear.

yes,your are right,may the old context is destroyed,but their memory never freed,after i return to app,the freememoy just freeed the new context's memory,the old context's memory will never free,although the old context was destroyed.


i have soled,in this way,meybe there is better solution?can you tell me?
public void onSurfaceChanged(GL10 gl, int width, int height)
{       
  fb.freememory;//unload old context's  framebuffer memory
   
  fb=null;
  fb=new frameeBuffer(width,height);
  ini_tex(fb);//initialize new context's framebuffer
  Config.unloadImmediately=true;                   
  texturemanage.removeAndUnload("a", fb);       
  texturemanage.removeAndUnload("c", fb);
   ................................................
  fb.freememory;
 }



Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: FrameBuffer.freememory sometimes useless?
« Reply #3 on: April 28, 2015, 11:49:46 am »
in onPause,i did nothing just super method

protected void onPause()
{
      
      super.onPause();
      mGLView.onPause();//GLSurfaceView mGLView
      
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: FrameBuffer.freememory sometimes useless?
« Reply #4 on: April 28, 2015, 11:17:34 pm »
Putting it at that position actually makes no sense, because in onSurfaceChanged, the old GL context is already invalid. Even if it actually prints out some messages, it doesn't really free stuff because it's working in a different context, where these textures don't exist. In addition, I don't quite understand why people are so keen on un- and reloading everything on pause or stop.
Here's what I do and it works fine for me: Load all textures once and leave them be. Call setPreserveEGLContextOnPause(true); on your GLSurfaceView and store the last gl instance. In onSurfaceChanged, check if the new instance is different from the old and only if it is, create a new FrameBuffer. That's all i'm doing. I don't see the need to constantly load and unload stuff. If the gl context gets destroyed (which can happen with setPreserveEGLContextOnPause(true); as well in some situations), the native memory used for the textures will be freed by the driver anyway. It has to be this way. Everything else would kill the OS after some time.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: FrameBuffer.freememory sometimes useless?
« Reply #5 on: April 29, 2015, 04:45:30 am »
yes,yes,the very key is the GLSurfaceView.setPreserveEGLContextOnPause(true);it solved my problem perfectly.
Giant appreciation to you ego,Nothing i can see,without thx.