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

first look at PolynomB in *LinearPass #290

Merged
merged 1 commit into from
Sep 20, 2021
Merged

Conversation

swhite2401
Copy link
Contributor

This branches fixes memory leaks in *LinearPass relating to the property K pointing to PolynomB[1].
Changes should be transparent for matlab, @lfarv could you please confirm?

@lfarv
Copy link
Contributor

lfarv commented Sep 10, 2021

@swhite2401 :

  1. There is one small difference, for both Matlab and python: in the original version, we look 1st at attribute "K", and if it is not available, then at "PolynomB". In the modified version, you look 1st at "PolynomB", and then at "K". In python, "K" is derived from "PolynomB", so it does not matter. In Matlab, it may make a difference if K and PolynomB are inconsistent, but this is an error, it should not happen… So no problem for me.
  2. Now you avoid calling atGetOptionalDouble(ElemData,"K",0) if PolynomB is defined, but this raises a much more severe problem: if all atGetSomething functions block a reference, we have a big problem…

Apparently, indeed, PyObject_GetAttrString returns a 'new reference', so we should DECREF each attribute after use. For "scalar" values, we can do it immediately in the atGetSomething function. But for arrays where we return a pointer, we must keep the reference until atpass is called again with a "new lattice". And we don't keep the pointers to the attribute PyObjects…

We could anyway release immediately the attribute objects, and hope that no python piece of code, called by 'atpass' removes any element attribute until the tracking is finished (it would make no sense, but who knows…).

Or better we could keep in atpass a reference to the element itself, and DECREF immediately its attribute objects. Then we are protected from the case where the element is removed from the Lattice while tracking goes on, or even if the Lattice itself is removed. Remains the case where someone (python code) would remove explicitly an attribute from an element during tracking.

Summary: for me you can merge, but this only solves a very small part of the problem!

@swhite2401
Copy link
Contributor Author

thanks @lfarv, I have no better solution for the more general problem although the situation you describe is quite unlikely (but who knows as you say...).
I can leave this branch open for discussion and potential improvements, these passmethods are not used that much anymore, I did run into this by chance so there is no rush to merge.
Maybe @willrogers would have a good proposal?

@swhite2401
Copy link
Contributor Author

Should I merge this one too before #296 ?

@lfarv lfarv mentioned this pull request Sep 17, 2021
@lfarv
Copy link
Contributor

lfarv commented Sep 19, 2021

The memory leak problem is more generally solved in #299

@willrogers
Copy link
Contributor

willrogers commented Sep 19, 2021 via email

@lfarv
Copy link
Contributor

lfarv commented Sep 19, 2021

This PR is replaced by #299 and can be closed.

@swhite2401 swhite2401 changed the title fixes memory leaks in *LinearPass for pyAT first look at PolynomB in *LinearPass Sep 20, 2021
@swhite2401
Copy link
Contributor Author

Very nice, however I agree with @willrogers that the logic is better this way around as it is more coherent with other passmethods. I changed the title to avoid confusion.
Unless you have objection I will merge this one today

@willrogers willrogers merged commit eb84214 into master Sep 20, 2021
@willrogers willrogers deleted the mem_leak_linearpass branch September 20, 2021 08:30
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.

None yet

3 participants