This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Embedded Python memory leak
Type: behavior Stage:
Components: Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Asesh, amaury.forgeotdarc, christian.heimes, jcea, loewis, vstinner
Priority: normal Keywords:

Created on 2011-11-17 00:57 by Asesh, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cScripting.zip Asesh, 2011-11-17 00:57 Project file along with static library and DLL
Messages (8)
msg147785 - (view) Author: Asesh (Asesh) Date: 2011-11-17 00:57
Well I just finished embedding Python in my application but even after calling Py_Finalize the debugger shows tons of memory leak. I just called Py_Initialize and then Py_Finalize then after exiting the application, the Visual C++ debugger shows tons of memory leaks and Python is to be blamed:

Detected memory leaks!
Dumping objects ->
{3478} normal block at 0x00000000026343E0, 912 bytes long.
 Data: <       po       > 00 00 00 00 00 00 03 70 6F FB FB FB FB FB FB FB 
{3476} normal block at 0x0000000002633DA0, 912 bytes long.
 Data: <       po       > 00 00 00 00 00 00 03 70 6F FB FB FB FB FB FB FB 
{3474} normal block at 0x000000000261AC70, 912 bytes long.
 Data: <       po       > 00 00 00 00 00 00 03 70 6F FB FB FB FB FB FB FB 
{3472} normal block at 0x000000000261A620, 912 bytes long.
 Data: <       po       > 00 00 00 00 00 00 03 70 6F FB FB FB FB FB FB FB 
{3471} normal block at 0x000000000261B540, 912 bytes long.
 Data: <       po       > 00 00 00 00 00 00 03 70 6F FB FB FB FB FB FB FB 
{3470} normal block at 0x00000000025C66B0, 800 bytes long.
 Data: <        m       > 00 00 00 00 00 00 03 00 6D FB FB FB FB FB FB FB 
... // Skipped posting more memory leaks
...

{63} normal block at 0x0000000001D927D0, 108 bytes long.
 Data: <C : \ U s e r s > 43 00 3A 00 5C 00 55 00 73 00 65 00 72 00 73 00 
Object dump complete.
The program '[6696] cScripting.exe: Native' has exited with code 0 (0x0).

Upon Googling, seems like am not the only one. I have attached a small project that demonstrates it. It's a x64 build and you'll have to adjust the path of the lib folder
msg147786 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-11-17 01:00
(The project example uses _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF) to perform memory leak check.)
msg147791 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011-11-17 08:05
These are not memory leaks, but global state that the Python interpreter does not bother to free on exit. The amount of memory there is limited.

Yes, I agree that this makes the basic memory checker built in Visual Studio completely useless.
msg147793 - (view) Author: Asesh (Asesh) Date: 2011-11-17 10:37
ok thanks for the replies. Actually I have python embedded in my game but now the real problem now is how do I differentiate from the real memory leak caused either by Python or by my application? Disabling memory leak check is not an option since it's been very helpful when debugging my C++ apps
msg147981 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-11-20 10:11
If you *really* want to solve this problem, you could start working on making Python release all memory at interpreter shutdown. Please understand that this project may well take several years to complete, but it would help not only your project, but also many people in a similar situation.

Meanwhile, you should use a better memory checker, one where you can declare that it shall ignore certain allocations.
msg148045 - (view) Author: Asesh (Asesh) Date: 2011-11-21 14:39
@Martin v. Löwis (loewis): thanks, I will try to do so in my free time
msg192674 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-08 17:11
Martin, can we close this issue or do you want to keep it around?
msg192757 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2013-07-09 15:13
Ok, closing it.
History
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57627
2013-07-09 15:13:04loewissetstatus: languishing -> closed

messages: + msg192757
2013-07-08 17:11:08christian.heimessetstatus: open -> languishing

nosy: + christian.heimes
messages: + msg192674

resolution: wont fix
2011-11-21 14:39:44Aseshsetmessages: + msg148045
2011-11-20 10:11:11loewissetnosy: + loewis
messages: + msg147981
2011-11-17 10:37:34Aseshsetmessages: + msg147793
2011-11-17 08:05:16amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg147791
2011-11-17 01:45:29jceasetnosy: + jcea
2011-11-17 01:00:22vstinnersetnosy: + vstinner
messages: + msg147786
2011-11-17 00:57:33Aseshcreate