Does Boost.Python participate in cyclic gc?

skip at pobox.com skip at pobox.com
Tue Jun 5 15:32:14 EDT 2007


We encountered a situation today where it appeared that a
Boost.Python-provided class didn't participate in Python's cyclic garbage
collection.  The wrapped C++ instance held a reference to a method in the
Python object which referenced the Boostified C++ instance, e.g.:

    class Foo:
        def __init__(self, ...):
            self.over_there = BoostifiedClass()
            self.over_there.set_callback(self.boost_callback)
            ...

        def boost_callback(self, ...):
            ...

When an instance of Foo went out of scope the BoostifiedClass instance it
referred to didn't disappear.  (We could tell because it made connections to
another server which didn't disappear.)  The solution was to recognize when
we where finished with it to set self.over_there to None.  It would be nice
if Boost.Python knew how to play in the gc sandbox, but I suspect it may
not.

Thx,

Skip




More information about the Python-list mailing list