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: Python will not co-exist with MFC (memory leak)
Type: resource usage Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, loewis, nqiang
Priority: normal Keywords:

Created on 2009-01-07 21:55 by nqiang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg79375 - (view) Author: nqiang (nqiang) Date: 2009-01-07 21:55
The following code will cause memory leak in debug mode using visual 
studio 2008/2005
Comment out either MFC related (CString s) or Python related PY_XX. 
Then there will be no memory leak.

#include <python.h>
#include <afx.h>


int _tmain(int argc, _TCHAR* argv[])
{
	Py_Initialize();
	Py_Finalize();
	CString	s;
	return 0;
}
msg79377 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-07 22:27
How do you know that there is a memory leak? 

I find it very unlikely that this interaction could cause a memory leak
(although it is plausible that in this case, not all memory is returned
to the system - which is something different from a memory leak).
msg118034 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-10-05 21:32
- The "memory leaks" are reported in the IDE output window when the process exits; this lists all non deallocated blocks of memory.  This feature is not enabled by default.  Creating a CString probably initializes this feature.

- Py_Finalize() doesn't free all memory used by Py_Initialize(); this is not a problem, as long as a second call to Py_Initialize() reuses the same memory.

Closing as "won't fix": there is no need to free everything when the process exits.
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49122
2010-10-05 21:32:09amaury.forgeotdarcsetstatus: pending -> closed

nosy: + amaury.forgeotdarc
messages: + msg118034

resolution: not a bug -> wont fix
2010-06-25 22:34:25terry.reedysetstatus: open -> pending
resolution: not a bug
versions: - Python 2.5, Python 3.0
2009-01-07 22:27:49loewissetnosy: + loewis
messages: + msg79377
2009-01-07 21:55:31nqiangcreate