-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Memory leaks in MFC dialog base application when use scoped_interpreter #2062
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
Comments
Well, I did a little dig. Then I found in 'internals.h' file, the function 'PYBIND11_NOINLINE inline internals &get_internals() ' there is a code block (line 272 ~ 274 ):
Find out internals_pp is a pointer that point to another pointer. But only release the *internals_pp pointer, not release the internals_pp pointer. After I add release internals_pp pointer , there is not more leak. Before fix, release code is : if (*internals_ptr_ptr) { After fix , release code is : if (*internals_ptr_ptr) { if (internals_ptr_ptr) { Sorry, for my poor English. I wish that make you clear the leak. |
I can confirm there is a memory leak, even without MFC. pybind11/include/pybind11/detail/internals.h Line 272 in 4f72ef8
|
We know about this. Help is needed. |
The example code in VC 2017 give a leak tip in debug mode.
Output windows show text like this:
Detected memory leaks!
Dumping objects ->
{266} normal block at 0x00C9B4E8, 4 bytes long.
Data: < > 00 00 00 00
Object dump complete.
I had try the code in Win32 Application, it's OK, no leak.
The version of Visual Stuido 2017 I'm using is 15.9.16.
It seem the "internals_pp" pointer did not release.
In "internals.h" file of function "inline internals **&get_internals_pp() ".
Reproducible example code
namespace py = pybind11;
py::scoped_interpreter guard{};
auto dtPassTo = py::dict();
auto global = py::dict(py::module::import("main").attr("dict"));
dtPassTo["msg"] = py::cpp_function(
[](std::string strMsg) {
::MessageBoxA(nullptr, strMsg.c_str(), "", MB_OK);
});
py::exec("msg('test')", global, dtPassTo);
The text was updated successfully, but these errors were encountered: