Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Fixed memory leak in contour#6942
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Ian, thanks for the instantaneous response! I will leave the review to@mdboom and/or@tacaswell; I'm not competent in the C++ realm. |
👍 The explanation and fix both make sense and seem correct to me. Defer to@mdboom on if there is better way. Good thing I have not gotten to tagging a 1.5.3 yet. |
a 2.0.0b4 with this fix would be nice |
FIX: Fixed memory leak in contour
backported to v1.5.x as45243eb |
Fixed memory leak in contour as reported in#6940. PR is based on v2.x branch, but fix needs to be in all active branches.
Problem is down to my stupidity when adding numpy arrays to python lists to return from contour/contourf calls. New contouring C++ code uses our numpy
array_view
wrappers, which are in charge of their own reference counting, and native Python/C API list functions for which I am explicitly responsible for reference counting. Consider code:This is fine, but I am using
PyList_Append
instead ofPyList_SetItem
as I don't know the length of the list when it is created. It turns out thatPyList_Append
increments the reference count whereasPyList_SetItem
steals a reference. I assume I used to know this but have since forgotten it and have just rediscovered it.There are 2 options for the fix. Either
array_view.pyobj()
but store the returned object and decrement the reference count myself, orarray_view.pyobj_steal()
that returns a stolen reference.I've opted for the second option as that keeps all the explicit array reference counting within the
array_view
class.