Open vdng9338 opened 2 years ago
I didn't intend to close this PR -- looks like something weird happened.
If you're compiling with g++, compile with address sanitizer ( -fsanitize=address and link against libasan), e.g. for examples/surface.cpp
g++ -g -Wall -fsanitize=address -o surface $(python-config --includes) surface.cpp $(python-config --ldflags --embed) -lasan
This will show you all memory leaks. Before your changes, and after.
In a program I wrote, I had to plot a few hundreds of matplotlib plots, and memory usage went up to 5 Gb despite calling
plt::clf()
andplt::close()
after each plot. Removing all instances ofPy_INCREF
seems to solve the issue, sincePy_INCREF
is not needed on return values ofPyObject_GetAttrString
andPyObject_Call
, according to https://docs.python.org/3/extending/extending.html#ownership-rules.