File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,6 @@ initnoddy(void)
3737 nt -> tp_doc = "Noddy objects" ;
3838 if (PyType_Ready (nt ) < 0 )
3939 return ;
40-
40+ Py_INCREF ( nt ); /* For PyModule_AddObject to steal. */
4141 PyModule_AddObject (m , "Noddy" , (PyObject * ) nt );
4242}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ PyInit_noddy(void)
3737 nt -> tp_doc = "Noddy objects" ;
3838 if (PyType_Ready (nt ) < 0 )
3939 return NULL ;
40-
40+ Py_INCREF ( nt ); /* For PyModule_AddObject to steal. */
4141 PyModule_AddObject (m , "Noddy" , (PyObject * ) nt );
4242 return m ;
4343}
Original file line number Diff line number Diff line change 22from __future__ import division
33from __future__ import print_function
44
5+ import gc
56import sys
67
78import noddy
@@ -17,6 +18,10 @@ class NoddyPlus(noddy.Noddy):
1718 NoddyPlus = None
1819
1920
21+ def show_refcount ():
22+ print ('REFCOUNT:' , sys .getrefcount (noddy .Noddy ))
23+
24+
2025def exercise (output ):
2126 output (noddy )
2227 output (dir (noddy ))
@@ -32,12 +37,23 @@ def exercise(output):
3237
3338
3439def run (args ):
40+ print (sys .version )
41+ show_refcount ()
3542 exercise (print )
43+ show_refcount ()
44+ objs = []
45+ for unused_index in range (10 ):
46+ objs .append (noddy .Noddy ())
47+ show_refcount ()
48+ del objs
49+ gc .collect ()
50+ show_refcount ()
3651 if args :
3752 while True :
3853 def noop (unused_obj ):
3954 pass
4055 exercise (noop )
56+ show_refcount ()
4157
4258
4359if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments