Python types (including extension types) are reference counted, which
is why you don't have to do manual memory management in Python.
However, as the C++ layer doesn't know about Python's memory
management, it doesn't do the right thing when you try to put them
into a C++ STL container. There are two standard options here:
(1) Cast them to a PyObject* and keep track of the reference counting
(Py_INCREF/Py_DECREF) manually, just as you would if you were not
using Cython.
(2) Write a "smart pyobject pointer" class to encapsulate python
objects and do reference counting automatically. There's been talk of
providing this automatically in Cython.
- Robert