From: Ben W. <be...@sa...> - 2009-04-16 20:04:44
|
Josh Cherry wrote: > On Wed, 15 Apr 2009, Ben Webb wrote: >> So, the C++ object still exists but the Python one is still being freed >> prematurely. This is the problem I am trying to solve. > > How about something like this: > > %pythonprepend FooHolder::set_foo %{ > args[0].foo = args[1] > %} We are thinking along similar lines here. ;) Yes, I was thinking of something like that. But I have two problems with it: 1. I would have to modify all such methods to add a Python reference, and we have a large number of such methods. (Furthermore, since 99% of our objects are pure C++, not directors, I should only do this for director objects, so that the heap is not littered with Python proxies.) More tricky I think would be modifying all of the relevant remove functions, destructors etc. to remove these references at the right time. But this is not an insurmountable problem. 2. In the more general case we may have something like FooHolderHolder -> FooHolder -> Foo i.e. a reference to FooHolder is in turn held by another C++ class. Only Foo is a director class, so while the C++ FooHolder and FooHolderHolder object lifetimes are managed by our C++ code, the Python proxies for them could potentially disappear. But because the .foo reference is stored by the FooHolder proxy, if this proxy disappears the Foo director object will too. So we'd to do something similar to keep references to the FooHolder and so on. Ben -- be...@sa... http://salilab.org/~ben/ "It is a capital mistake to theorize before one has data." - Sir Arthur Conan Doyle |