Destroying a buffer
When a buffer is no longer used, we should destroy it.
How to do it...
- Take the handle of a logical device and store it in a variable of type
VkDevice
namedlogical_device
. - Store the buffer's handle in a variable of type
VkBuffer
namedbuffer
. - Call
vkDestroyBuffer( logical_device, buffer, nullptr )
and provide the handle of the logical device, the handle of the buffer, and anullptr
value. - For safety reasons, assign the
VK_NULL_HANDLE
value to thebuffer
variable.
How it works...
Buffers are destroyed using the vkDestroyBuffer()
function like this:
if( VK_NULL_HANDLE != buffer ) { vkDestroyBuffer( logical_device, buffer, nullptr ); buffer = VK_NULL_HANDLE; }
logical_device
is a variable representing the logical device on which the buffer was created. When we destroy a buffer, we assign an empty handle to the variable representing this buffer, so we won't try to destroy the same resource twice.
See also
- Creating a buffer view recipe in this chapter