Int tuple element scope

Ron Griswold ron at projectmessiah.com
Mon May 10 23:17:39 EDT 2004


Can anyone tell me why the following will cause the returned tuple elements to remain un collected when the tuple goes out of scope:

PyObject * iobj = PyObject_New( PyIntObject, &PyInt_Type );
iobj->ob_ival = val;
PyTuple_SetItem( tuple, index, iobj );
return tuple;

while the following will collect the elements:

PyTuple_SetItem( tuple, index PyInt_FromLong( val ) );
return tuple;

both PyObject_New and PyInt_FromLong return new references and I have verified that in all cases the refcount upon return is 1 for all objects involved. So I'm just wondering if I'm missing something fundamental.

Thanks in advance!

Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040510/bbbb0de7/attachment.html>


More information about the Python-list mailing list