On Wed, 22 May 2013 23:18:53 +0600, Czarek Tomczak
<
czarek....@gmail.com> wrote:
> I have to keep PyWebRequests in C++ map as I do not want to increase
> references
> to these objects, I need to access them from C++ and I do not have
> control over their lifetime, keeping them in a Python dict would make
> them live forever and the memory would never be freed.
Weak references exist specifically for this purpose.
They are also much safer, because they are cleared automatically
when the pointed object dies.
Take a look at WeakValueDictionary in the standard lib.
Note: cdef classes need an additional member ("cdef __weakref__")
in order to support weak references.
(
http://docs.cython.org/src/reference/extension_types.html#weak-referencing)
Language-level weakref support and weakref optimizations are on my
personal Cython wishlist...
Best regards,
Nikita Nemkin