memory leak - C API
Tim Peters
tim.one at comcast.net
Fri Dec 5 14:41:03 EST 2003
More information about the Python-list mailing list
Fri Dec 5 14:41:03 EST 2003
- Previous message (by thread): memory leak - C API
- Next message (by thread): memory leak - C API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[John Hunter]
> ...
> My understanding is that PySequence_GetItem returns a borrowed ref so I
> don't need to do any memory management.
Where did that understanding come from? It's important to track it down,
because whatever source you got it from is unreliable. This one is such a
common misconception that the docs (Python C/API Reference Manual, section
"Reference Count Details") point it out explicitly:
It is important to realize that whether you own a reference returned
by a function depends on which function you call only -- the plumage
(the type of the object passed as an argument to the function) doesn't
enter into it! Thus, if you extract an item from a list using
PyList_GetItem(), you don't own the reference -- but if you obtain the
same item from the same list using PySequence_GetItem() (which
happens to take exactly the same arguments), you do own a reference
to the returned object.
- Previous message (by thread): memory leak - C API
- Next message (by thread): memory leak - C API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list