On Tue, Aug 2, 2011 at 3:00 AM, Nat Goodspeed <[hidden email]> wrote:

http://docs.python.org/library/weakref.html#module-weakref

 
Unfortunately, I can't use `weakref` I already tried that, but the problem is that the weak references get deleted (and their value set to `None`) before `__del__` is called. So when `removeEventHandler` is called, it won't be able to find the weakref it's supposed to remove (because its value has been changed to `None`).

To fix, this would require some special handling of Python function objects in the `EventManager` — I don't want that, I wish to keep the manager agnostic to Python since I'm going to be pushing events into it from both C++ and Python. I'd like to solve this problem exclusively through the `EventManager` wrapper class I wrote.


On Tue, Aug 2, 2011 at 3:24 AM, Jim Bosch-2 [via Boost] <[hidden email]> wrote:

Are these cycles actually a problem in practice?  Python does do garbage
collection, so it might be that it knows about all these dependencies
and just hasn't bothered to try to delete them because it doesn't need
the memory yet.


 Yes, they are problematic. When the object gets removed it should not receive any more events or it will very likely result in some odd behavior on the screen. These objects are entity states in a game. A state dictates how an entity reacts to game events and when the entity changes its state, the old one should stop giving the entity instructions, or they will conflict with the instructions given by the new state.


View this message in context: Re: Boost.Python: Callbacks to class functions
Sent from the Python - c++-sig mailing list archive at Nabble.com.