Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Release method wrapper(split from #958) #1002

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

Merged
merged 5 commits into from
Dec 18, 2019

Conversation

amos402
Copy link
Member

@amos402 amos402 commented Nov 30, 2019

What does this implement/fix? Explain your changes.

Release method wrapper and module definition(Python3) when shutdown

Does this close any currently open issues?

...

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

@codecov-io
Copy link

codecov-io commented Nov 30, 2019

Codecov Report

Merging #1002 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1002   +/-   ##
=======================================
  Coverage   86.71%   86.71%           
=======================================
  Files           1        1           
  Lines         301      301           
=======================================
  Hits          261      261           
  Misses         40       40
Flag Coverage Δ
#setup_linux 65.44% <ø> (ø) ⬆️
#setup_windows 71.42% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba5127a...27f72cd. Read the comment docs.

bool shouldFreeDef = Runtime.Refcount(py_clr_module) == 1;
Runtime.XDecref(py_clr_module);
py_clr_module = IntPtr.Zero;
#if PYTHON3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid introducing another compile-time check, and use version info from Runtime class instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, in the modernisation branch I gave up on the idea of having Python 2 and 3 in the same codebase, especially considering the imminent EoL of Python 2. I do that by defaulting to Python 3 and letting the user supply PYTHON2 explicitly for the Py2 version. So here, to stay in line with that, it would be enough to change to #if !PYTHON2.

Comment on lines +43 to +49
bool freeDef = Runtime.Refcount(ptr) == 1;
Runtime.XDecref(ptr);
if (freeDef && mdef != IntPtr.Zero)
{
Runtime.PyMem_Free(mdef);
mdef = IntPtr.Zero;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we call Release, and there are still references to the method, how is it going to be freed later?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amos402 Could you comment on this question?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't release anymore, here's the only chance for now. Assume the ptr deallocating in another domain in the future, the cod in this domain had already been invalid, unless we use a C extension take place the ptr's tp_dealloc.

@filmor filmor merged commit c1190f4 into pythonnet:master Dec 18, 2019
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull request Jun 27, 2020
* Add exception helper
* Release memory on ImportHook.Shutdown
* Release ModuleDef when py_clr_module released
* Completely ModuleDef initialization
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.

4 participants