Int tuple element scope

R

Ron Griswold

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top