[wxPython-dev] Problem with MenuItem.Destroy()
Paul McNett
p at ulmcnett.com
Fri Dec 22 14:04:15 PST 2006
Robin Dunn wrote:
> In a nutshell the problem is this: The wx.MenuItem class isn't able to
> use the OOR capabilities that I can use for wx.Window and etc., so the
> normal SWIG proxy mechanisms are used instead. So that means that each
> time a wx.MenuItem is returned from a method a new Python proxy object
> is created for it, even if one wrapping the same C++ object already
> exists. Normally this is all transparent and we don't care about it,
> but object ownership rules are tossing a spanner in the works here...
> AppendItem takes ownership of the C++ object, so I set a flag that tells
> the proxy object that it no longer owns the C++ object and so it doesn't
> try to destroy it when the proxy is GC'd. However RemoveItem
> relinquishes ownership of the C++ object, so the proxy used for the
> return value is set to own the C++ object. In your original code since
> you were not assigning the return value proxy to a variable it was
> getting GC's immediately and so the C++ object was being destroyed.
> However since the proxy used for the parameter points to the same (now
> destroyed) C++ object when you try to use it for the next AppendItem you
> get the segfault.
>
> Since we know that with RemoveItem that the parameter and the return
> value will always be the same C++ object I think that there should be a
> way that I can fix this such that either code snippet will work as
> expected. I'll see what I can do.
Thank you for the full explanation Robin. I wish I had more available
time (as in somebody paying me <g>) in which case I'd start learning the
wxWidgets internals and be better able to actually assist.
But the main question on my mind now is: what changed in wxPython
2.7/2.8 versus 2.6 that didn't show these problems?
--
pkm ~ http://paulmcnett.com
More information about the wxpython-dev
mailing list