public void Dispose() { if (PerInflightFrameAllocators != null) { // Make sure that it is allowed to destory the Allocators. swapChain.WaitUntilAllFramesCompleted(); swapChain.RemoveRef(); swapChain.OnBeginFrame -= SetActiveAllocator; foreach (var alloc in PerInflightFrameAllocators) { alloc.RemoveRef(); alloc.Dispose(); } PerInflightFrameAllocators = null; } }