RESOLVED: Cpp Python Parameter Memory Leak

Hi there,

I think I discovered a memory leak, when using a custom Python parameter in a cppCHOP.
I made a very simple example you can download here: https://drive.google.com/open?id=1x5yvZRuA4sDi2DW9TMaPVuyhnix0Lbj-

I only changed the example cppCHOP by adding a Python parameter.
Open the included toe and observe the RAM used by TD.

Best wishes,
David

build 2019.36500

Thanks, we’re having a look.

So it’s not actually a memory leak.
Recreating the plugin will recreate the custom parameters, keeping the old ones in case they are referenced by other objects.

You’ll see that increase in memory for any custom parameter, not just python, when re-initializing the plugin.

One potential memory leak though:

PyObject* parent = inputs->getParPython("Parent");

You should dealloc this evaluation when done with it:

Py_XDECREF(parent);

Cheers.

Thanks for having a look rob!

Good to know, that custom parameters have this effect.

About the deallocation of the Python object - the docs says not to do it, should I use Py_XDECREF anyway?

Cheers

// The returned object does NOT have it’s reference count incremented.
// So increment it if you want to hold onto the object, and only
// decement it if you’ve incremented it.
virtual PyObject* getParPython(const char* name) const = 0;

1 Like

Ah, thanks for pointing that out.

After reviewing the code, looks like that documentation is incorrect.
Object should definitely should be deallocated.

We’ll fix it.
Cheers.