protected override void Cleanup() { if (!ReferenceEquals(memory, null)) { memory.Dispose(); memory = null; } }
/// <summary> /// Free managed memory. This method does nothing if it is not owner of origin memory block. /// </summary> /// <param name="disposing">If this instance is the owner of the memory block it will always release the origin memory block to avoid memory leaks. If you don't want this, don't call this method (<see cref="Dispose(bool)"/>) in your derived class.</param> protected virtual void Dispose(bool disposing) { if (disposing) { // free managed here } if (owner) { memoryLength = 0; memoryPointer = IntPtr.Zero; memoryOffset = 0; memory.Dispose(); owner = false; } }
/// <summary> /// Dispose the instance. /// </summary> /// <param name="disposing">The memory will always be released to avoid memory leaks. If you don't want this, don't call this method (<see cref="Dispose(bool)"/>) in your derived class.</param> protected virtual void Dispose(bool disposing) { if (disposing) { // free managed stuff here } control.Rx = 0; control.Tx = 0; control.Length = 0; // always free managed/unmanaged memory if (!ReferenceEquals(txBuf, null)) { txBuf.Dispose(); } if (!ReferenceEquals(rxBuf, null)) { rxBuf.Dispose(); } }
public void Dispose() { internalMemory.Dispose(); }