Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged

Conversation

ianthomas23
Copy link
Member

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 numpyarray_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:

numpy::array_view<double, 2> line(dims);   // ref count 1PyObject* pyline = line.pyobj();  // ref count 2PyList_SetItem(pylist, pyline);  // ref count remains 2 as PyList_SetItem steals referencereturn pylist;  // line goes out of scope so ref count 1 for the one and only reference in the list

This is fine, but I am usingPyList_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

  1. keep usingarray_view.pyobj() but store the returned object and decrement the reference count myself, or
  2. use a new functionarray_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 thearray_view class.

@efiringefiring added this to the2.0 (style change major release) milestoneAug 12, 2016
@efiringefiring added the Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labelAug 12, 2016
@efiring
Copy link
Member

Ian, thanks for the instantaneous response! I will leave the review to@mdboom and/or@tacaswell; I'm not competent in the C++ realm.

@tacaswell
Copy link
Member

👍 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.

@tacaswelltacaswell merged commitf6d5303 intomatplotlib:v2.xAug 22, 2016
@stonebig
Copy link
Contributor

a 2.0.0b4 with this fix would be nice

tacaswell added a commit that referenced this pull requestSep 8, 2016
@tacaswell
Copy link
Member

backported to v1.5.x as45243eb

@QuLogicQuLogic modified the milestones:v1.5.x,2.0 (style change major release)Sep 9, 2016
@ianthomas23ianthomas23 deleted the 6940_contour_memory_leak branchJuly 8, 2021 18:22
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Milestone
v1.5.3
Development

Successfully merging this pull request may close these issues.

6 participants
@ianthomas23@efiring@tacaswell@stonebig@mdboom@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp