Does Boost.Python participate in cyclic gc?

skip at skip at
Tue Jun 5 21:32:14 CEST 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()

        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



More information about the Python-list mailing list