Skip to content

Commit 3dae553

Browse files
committed
show noddy.Noddy refcount
1 parent 54068a6 commit 3dae553

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

noddy/noddy_heaptype_py2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

noddy/noddy_heaptype_py3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

noddy/noddy_main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import division
33
from __future__ import print_function
44

5+
import gc
56
import sys
67

78
import 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+
2025
def exercise(output):
2126
output(noddy)
2227
output(dir(noddy))
@@ -32,12 +37,23 @@ def exercise(output):
3237

3338

3439
def 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

4359
if __name__ == '__main__':

0 commit comments

Comments
 (0)