Author Topic: Memory and replace texture  (Read 4924 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Memory and replace texture
« on: April 14, 2012, 06:05:37 pm »
When I use Texture.replaceTexture() method, original is probably still in memory. Can someone confirm it?

I have textures 512*512 and when is all replace by 128*128 memory increased to 42MB, before it was 35MB

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Memory and replace texture
« Reply #1 on: April 14, 2012, 07:57:57 pm »
Of course it is. That why the docs say:

Quote
...It might be required to call unloadTexture() before to ensure that the old texture has been unloaded from the GPU in case it's no longer used somewhere else.

 ;)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Memory and replace texture
« Reply #2 on: April 14, 2012, 08:31:35 pm »
Oh ;D ... I tried this, after everything are without texture

edit: now it is OK :)

Code: [Select]
Texture texture = tm.getTexture(name);
TextureManager tm = TextureManager.getInstance();
tm.unloadTexture(fb, texture);
tm.replaceTexture(name, newTexture);

before I remove old and add new texture

edit2: Allocated memory does not increased, but still same...?
« Last Edit: April 14, 2012, 10:28:04 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Memory and replace texture
« Reply #3 on: April 14, 2012, 11:16:23 pm »
edit2: Allocated memory does not increased, but still same...?
I don't understand... ???

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Memory and replace texture
« Reply #4 on: April 15, 2012, 01:04:43 am »
Allocated memory is not released, when I replace textures by much more smaller.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Memory and replace texture
« Reply #5 on: April 15, 2012, 08:15:18 pm »
Of course not. The VM doesn't release memory to the OS. If just frees internal VM memory. If you aren't holding a reference to this texture anymore, it will be garbage collected. No one else holds a reference to it in jPCT-AE. The engine only deals with IDs, it doesn't keep reference to the textures (with the exception of the TextureManager of course).