Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some memory leaks #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix some memory leaks #278

wants to merge 1 commit into from

Conversation

vdng9338
Copy link

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() and plt::close() after each plot. Removing all instances of Py_INCREF seems to solve the issue, since Py_INCREF is not needed on return values of PyObject_GetAttrString and PyObject_Call, according to https://docs.python.org/3/extending/extending.html#ownership-rules.

@vdng9338 vdng9338 deleted the branch lava:master July 28, 2021 15:16
@vdng9338 vdng9338 closed this Jul 28, 2021
@vdng9338 vdng9338 deleted the master branch July 28, 2021 15:16
@vdng9338 vdng9338 restored the master branch July 28, 2021 15:17
@vdng9338
Copy link
Author

vdng9338 commented Aug 8, 2021

I didn't intend to close this PR -- looks like something weird happened.

@vdng9338 vdng9338 reopened this Aug 8, 2021
@amadeus84
Copy link

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.

Gonzalo-Mier added a commit to Fields2Cover/matplotlib-cpp that referenced this pull request Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants