Still have the issue. Anyone can help?

On Mon, Feb 10, 2014 at 10:08 AM, Olivier Voyer <> wrote:

I'm facing a memory management issue while wrapping C++ to Python using SWIG.

Here is the problem.

My C++ code (.h):

#ifdef SWIG
Element* getElement(); // Instatiates the Element object with correct values

class Element
  std::string ID;
    Member* Obj;

class Member
    double X;
    double Y;

When I use this inline command in Python, I get an undefined value, for example -2.65698425804e+303:

myX = getElement().Obj.X

But when I call this in two parts, I get the correct value:

myElement = getElement()
myX = myElement.Obj.X

It seems that the Object pointer gets garbage collected when using the inline command, but I can't find a way to avoid this.

Any idea?