private void Dispose(bool callFromUserCode) { if (callFromUserCode) { this.isDisposed = true; } // If for whathever reason, the handle was not initialized correctly (e.g. an exception // in the constructor), we shouldn't free it either. if (this.transformHandle != IntPtr.Zero) { TurboJpegImport.TjDestroy(this.transformHandle); // Set the handle to IntPtr.Zero, to prevent double execution of this method // (i.e. make calling Dispose twice a safe thing to do). this.transformHandle = IntPtr.Zero; } }