logo       

SWIG - Memory leak: msg#00174

programming.swig

Subject: SWIG - Memory leak

Hi there, I have a problem with a very simple extended swig function.
I'll try to make this as short as possible so here it is:

In my C Code, I define the following:
typedef float REAL32;

I want to export a C function to swig that has the following prototype:
void somefunction(REAL32 param1);

Lets say my module is called : mymodule, in python I cant call write the
following code:
import mymodule
mymodule.somefunction(1.0)
because it is telling me that I pass the wrong argument type. So I
created a simple typecasting function that maps a float to a REAL32,
even if it is casting to the same type (float = REAL32),

So I add the following in the %inline section of my mymodule.i file
REAL32 toREAL32(float value)
{
return (REAL32)value;
}
My Python function is an iterate function. It is called many times; in
my function I do the following:

def mypythonfunction():
number = mymodule.toREAL32(1.2)
return "ok"

If this function is called many times (thousands of), the program will
begin to leak and In approximatively 2 mins, It eats 10Megs of ram.

The weird thing is that if I define my typecasting function as the
following:
float toREAL32(float value)
{
return (float)value;
}
or float toREAL32(float value)
{
return value;
}

there is no memory leak at all. And the C meaning of this function is
the same as the 1st one since I have a typedef on REAL32 for float.

My code is called From a C++ program so the "hierarchy" is the
following:
C++ program
|
V
Python function
|
V
C toREAL32 function


Is it because I do something wrong? Is there another way of doing this ?

Thanks,

Mathieu Tremblay
mtremblay@xxxxxxxxxxxxx



_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise