The examples in LearnMetalCpp do in the renderer's draw method something like this:
- select a frame for the instance buffer
- create a new command buffer
- call dispatch_semaphore_wait to make sure that the selected instance buffer is not used by Metal
- put dispatch_semaphore_signal into the command buffer's completed handler
- modify the instance buffer and some other Metal related variables
- commit the command buffer
Depending on the number of frames used and the complexity of the scene there can be a couple of frames in the command queue. Suppose the window (and its related view) is closed while Metal is still busy with items in the command queue. This means that the semaphore is still in use.
How is it guaranteed that the semaphore is destroyed after the view is closed? Or is it guaranteed that the view's destructor is only called after the command queue has finished all its work?