Should VBO be unbound before calling glDeleteBuffers?

http://stackoverflow.com/questions/23564945/should-vbo-be-unbound-before-calling-gldeletebuffers#
The only time you would want to manually unbind a resource in GL prior to deletion is if you have it bound in a separate context. That is because one the criteria for actually freeing the memory associated with a GL resource is that it have a reference count of 0. glDelete* (…) only unbinds an object from the current context prior to putting it on a queue of objects to free.
If you delete it while a VAO that is not currently bound holds a pointer to this buffer, or if it is bound in a completely different OpenGL context from the one you call glDelete* (…) in, then the reference count does not reach 0 before glDelete* (…) finishes. As a result, the memory will not be freeduntil you actually unbind it from or destroy all VAO / render contexts that are holding references. You will effectively leak memory until you take care of all the dangling references.
In short, glDelete* (…) will always unbind resources from the current context and reclaim any names for immediate reuse, but it will only free the associated memory if after unbinding it the reference count is 0.
In this case, unbinding is completely unnecessary because you are doing so in the same context you call glDeleteBuffers (…) from. This call implicitly unbinds the object you are deleting, so you are doing something redundant. What is more, you already deleted your VAO prior to calling glDeleteBuffers (…) – when that VAO was deleted, it relinquished all of its pointers and thus decremented the reference count to your buffer.

The only time you would want to manually unbind a resource in GL prior to deletion is if you have it bound in a separate context. That is because one the criteria for actually freeing the memory associated with a GL resource is that it have a reference count of 0. glDelete* (…) only unbinds an object from the current context prior to putting it on a queue of objects to free.
If you delete it while a VAO that is not currently bound holds a pointer to this buffer, or if it is bound in a completely different OpenGL context from the one you call glDelete* (…) in, then the reference count does not reach 0 before glDelete* (…) finishes. As a result, the memory will not be freeduntil you actually unbind it from or destroy all VAO / render contexts that are holding references. You will effectively leak memory until you take care of all the dangling references.
In short, glDelete* (…) will always unbind resources from the current context and reclaim any names for immediate reuse, but it will only free the associated memory if after unbinding it the reference count is 0.
In this case, unbinding is completely unnecessary because you are doing so in the same context you call glDeleteBuffers (…) from. This call implicitly unbinds the object you are deleting, so you are doing something redundant. What is more, you already deleted your VAO prior to calling glDeleteBuffers (…) – when that VAO was deleted, it relinquished all of its pointers and thus decremented the reference count to your buffer.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值