[issue1545463] New-style classes fail to cleanup attributes

Alexander Belopolsky report at bugs.python.org
Tue Nov 11 06:23:55 CET 2008


Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:

amaury> What if PyGC_Collect() is called just before?

That would work.  With the following patch:

===================================================================
--- Python/import.c	(revision 67183)
+++ Python/import.c	(working copy)
@@ -498,7 +498,10 @@
 			PyDict_SetItem(modules, key, Py_None);
 		}
 	}
-
+	/* Collect garbage remaining after deleting the
+	   modules. Mostly reference cycles created by new style
+	   classes. */
+ 	PyGC_Collect();
 	/* Next, delete sys and __builtin__ (in that order) */
 	value = PyDict_GetItemString(modules, "sys");
 	if (value != NULL && PyModule_Check(value)) {

$ ./python.exe x.py
creating X('new')
creating X('old')
deleting X('old')
deleting X('new')

----------
keywords: +patch
Added file: http://bugs.python.org/file11983/gc-import.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1545463>
_______________________________________


More information about the Python-bugs-list mailing list