Handling IDisposable. #336
Unanswered
Gavin-Williams
asked this question in
Q&A
Replies: 1 comment
-
I was also wondering about this issue lately. Looking through the code in this repository I can't see dispose pattern implemented anywhere, like: Vortice.Windows/src/samples/HelloDirect3D12/ShaderIncludeHandler.cs Lines 88 to 96 in 9a6e9c4 I usually do implement the private void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
[...]
_swapChain?.Dispose(); //IDXGISwapChain4
_swapChain = null;
[...]
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~RenderingSurface()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
} But I am honestly unsure if that's the proper way to do it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've just discovered that VS has a quick action 'Implement interface with Dispose pattern' which is good, because I'm never quite sure how to implement it. Not that I understand the quick action pattern, but I'll just follow it's recommendations. However, the following questions come up..
Is Vortice object disposal considered managed or unmanaged? I'm not sure about the distinction, because presumably Vortice objects can internally configure whether they are picked up by the GC and handle any native object disposal appropriately.
And as a consequence of that. Should I uncomment this...
Beta Was this translation helpful? Give feedback.
All reactions