Freeing a memory object
In Vulkan, when we create resources, we later destroy them. On the other hand, resources that represent different memory objects or pools are allocated and freed. Memory objects bound to images and buffers are also freed. We should free them when we no longer need them.
How to do it...
- Take the logical device's handle and store it in a variable of type
VkDevice
namedlogical_device
. - Take the variable of type
VkDeviceMemory
namedmemory_object
, in which the handle of the memory object is stored. - Call
vkFreeMemory( logical_device, memory_object, nullptr )
. Use the handle of the logical device, the handle of the memory object, and anullptr
value. - For safety reasons, assign the
VK_NULL_HANDLE
value to thememory_object
variable.
How it works...
Memory objects can be freed before resources that were using them are destroyed. But we can't use these resources any more, we can only destroy them. In general, we can't bind one memory object to the resource, free it, and then bind...