I have a big C project and I want to expose it's API to python by using SWIG. For that, I have a script for generating automatically the interface file for swig (.i file). For each type defined in the project, the script adds to the interface file %pointer_functions and %array_functions for that type. Those directives create set of functions including a "new" function which in turn allocates memory. Is there a way to automatically deallocate that memory when the object is garbage collected instead of calling explicitly the "delete" function?
I have a solution for structs, using the %newobject directive and %extend with destructor definition which free the allocated memory - similar to the solution in this post SWIG - Garbage Collection using %newobject . But it doesn't work on primitive types like int, enum, etc... Any ideas how to solve it for such types?