private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { lock (this) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). if (_Color != null) { _Color.Dispose(); _Color = null; } if (_Depth != null) { _Depth.Dispose(); _Depth = null; } if (_IR != null) { _IR.Dispose(); _IR = null; } } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. handle.Close(); handle = null; disposedValue = true; } } }
/// <summary> /// Initializes a new instance of the <see cref="Capture"/> class. /// </summary> /// <param name="handle">Native handle of the Capture.</param> internal Capture(NativeMethods.k4a_capture_t handle) { // Hook the native allocator and register this object. // .Dispose() will be called on this object when the allocator is shut down. Allocator.Singleton.RegisterForDisposal(this); this.handle = handle; }
/// <summary> /// Handle the disposing of the object. /// </summary> /// <param name="disposing">true when called by Dispose(), false when called by the finalizer.</param> protected virtual void Dispose(bool disposing) { lock (this) { if (!this.disposedValue && disposing) { this.cachedColor?.Dispose(); this.cachedDepth?.Dispose(); this.cachedIR?.Dispose(); this.cachedColor = null; this.cachedDepth = null; this.cachedIR = null; this.handle.Close(); this.handle = null; Allocator.Singleton.UnregisterForDisposal(this); } this.disposedValue = true; } }
internal Capture(NativeMethods.k4a_capture_t handle) { this.handle = handle; }