7
\$\begingroup\$

If I call glDeleteTextures, will it release memory immediately? And what is the performance? I know that glGenTexture is quite cheap, because it only alocated id, but I have nor found anything about deleting.

\$\endgroup\$

1 Answer 1

10
\$\begingroup\$

If I call glDeleteTextures, will it release memory immediately?

glDeleteTextures

After a texture is deleted, it has no contents or dimensionality, and its name is free for reuse.

This says absolutely nothing about the backing storage for a texture, i.e the memory used for it. From that we can infer that behaviour is entirely up to the GL implementation. Typically one of three things might happen:

  • Memory is released immediately.
  • Memory is not released immediately but will be released at some point in time shortly after you call glDeleteTextures; a scenario where this might make sense is if releasing the memory immediately (and not returning until done) is an expensive operation - if so, queueing-up the release for later on might help with performance right now.
  • Memory is not released at all. Where this might make sense is if the memory can be re-used to satisfy a future allocation requirement and where this re-use is faster than a full release and reallocate cycle.

Because OpenGL doesn't specify which, any of these three, or something else entirely different, may happen.

Otherwise the only things you can rely on after calling glDeleteTextures are:

  1. The texture name can be reused by a future call to glGenTextures, and,
  2. glGet calls against the contents or dimensionality will return NULL or 0.

And what is the performance?

OpenGL specifies functionality, not performance. As always with performance-related questions, you should know your target platforms and benchmark/profile your code on them so that you are satisfied that the performance you get is within acceptable tolerances.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ There's a bigger story behind this: Drivers are required to behave as if the texture had been fully deleted, but otherwise they can get away with not fully deleting it if a performance optimization exists. You see a similar kind of behaviour with e.g early Z testing. \$\endgroup\$ Commented Feb 6, 2017 at 8:18
  • 1
    \$\begingroup\$ Some (strictly-speaking:buggy) drivers will even still render with that deleted texture if it has been previously configured in a shader sampler and not re-configured. Because no game / software should ever do that some drivers don't bother clearing/cleaning up/disabling the texture samplers in any of the (many) shaders as it would be a waste of time (performance) in properly behaving software. Eventually this will render whatever comes to replace it in GPU memory or even cause a memory access fault. If you ever see corrupted textures that can be the cause. \$\endgroup\$ Commented Feb 11, 2017 at 0:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .