Beginner's question about reference counts...

Miguel Marques miguel at apex.ccs.yorku.ca
Wed Jul 12 11:00:47 EDT 2000


Greetings...

I'm in the process of learning python and I have a question on writing
extensions.
Given the following code snippet where d is a Dict

  PyObject *newdict = PyDict_New();

  PyDict_SetItemString(d, "stuff", newdict);

Since I won't use newdict again in the function, I just want it to be
accessible through the 'd' dictionary, do I need to add a
Py_DECREF(newdict) after the PyDict_SetItemString?
I think I need to, because PyDict_SetItemString INCREFs both keys and
values and otherwise the reference count for newdict will off by one?
Is this the case or am I totally off the mark?
TIA

                                                        Miguel

-- 
C. Miguel Marques, York University, Computing & Communications Services
e-mail: miguel at yorku.ca, voice: (416)736-2100x22684, fax: (416)736-5830



More information about the Python-list mailing list