I have digging through the C# code generated by SWIG for Quantlib and came across the following code that gave me a humbling moment.
Each of the generated classes implement IDisposable, and each of the generated classes have this convention pointed out below.
public class MultiPath : IDisposable { // MultiPath is interchangable
private HandleRef swigCPtr;
protected bool swigCMemOwn;
internal MultiPath(IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
}
internal static HandleRef getCPtr(MultiPath obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
}
~MultiPath() { // <----
Dispose();
}
public virtual void Dispose() {
lock(this) {
if (swigCPtr.Handle != IntPtr.Zero) {
if (swigCMemOwn) {
swigCMemOwn = false;
NQuantLibcPINVOKE.delete_MultiPath(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
}
GC.SuppressFinalize(this);
}
}
// snip
}
If I'm reading this correctly, the bitwise complement operator is applied to the constructor of the class, so my questions are
~ operator in this example? Edit:
Just for clarity, the ~ is this case is called a Destructor. Thanks's @Arcturus.
Its the destructor!
In simple terms a destructor is a member that implements the actions required to destruct an instance of a class. The destructors enable the runtime system, to recover the heap space, to terminate file I/O that is associated with the removed class instance, or to perform both operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With