Add specific code to SWIG C# generated 'Dispose' method

lille stor <[email protected]> Thu, 21 Jan 2021 14:43:49 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <trinity-0e2a89aa-5806-490f-9e04-363d551a2645-1611236629342@3c-app-mailcom-bs01>
Hi,

I'm using SWIG to generate a C# wrapper of my C code. I can see that SWIG generates this method when the C# object is about to be disposed/finalized:

public virtual void Dispose() {
lock(this)
{
if (swigCPtr.Handle != global::System.IntPtr.Zero)
{

// *** add specific code here to call C function to release allocated memory ***

if (swigCMemOwn)
{
swigCMemOwn = false;
TestPINVOKE.delete_TestCursor(swigCPtr);
}
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
global::System.GC.SuppressFinalize(this);
}
}

However, I need to release allocated memory from the C side before the C# object is disposed/finalized (otherwise there is memory leaks on the C side). I have been looking at the available documentation but can't reach at any solution. The idea that I have is to call a C function to release the memory (please notice the comment embedded in the above code snippet).

All help is really appreciated. Thanks!

L.

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user