SWIG and dtors

Hi all,

I've created a .i file for wxMozilla and SWIGged it successfully. However,
I've noticed that I get an access violation on shutdown when I add the
~wxMozillaBrowser dtor to the interface. (it happens when
'delete_wxMozillaBrowser(_arg0) is called) If I leave it out, everything
seems to work fine.

Looking over some of the other SWIG .i files for wxPython I've noticed that
some modules do have their dtors listed, others don't. It seems that when
shutting down, wxWindows calls the dtors for all child objects itself. (I
noticed in the crash log that DeletePendingObjects was called before the
crash.) Should dtors always be added to the SWIG interface files, or should
this be omitted in most cases? I just want to make sure I'm not doing
something really bad by leaving out the dtor. =)

The good news is that up until shutdown, wxMozilla behaves just like it's
wxWindows counterpart. :slight_smile:

Thanks,

Kevin

Kevin Ollivier wrote:

Hi all,

I've created a .i file for wxMozilla and SWIGged it successfully. However,
I've noticed that I get an access violation on shutdown when I add the
~wxMozillaBrowser dtor to the interface. (it happens when
'delete_wxMozillaBrowser(_arg0) is called) If I leave it out, everything
seems to work fine.

Looking over some of the other SWIG .i files for wxPython I've noticed that
some modules do have their dtors listed, others don't. It seems that when
shutting down, wxWindows calls the dtors for all child objects itself.

Yep. When a wxWindow is destroyed then it first destroys all it's children. In other words, the window "owns" the objects for the child windows and so it manages their lifetime. The python reference doesn't own the object any more so the easiest way to not have it deleted when the python object is destroyed is no not specify the C++ dtor to SWIG.

(I
noticed in the crash log that DeletePendingObjects was called before the
crash.) Should dtors always be added to the SWIG interface files, or should
this be omitted in most cases? I just want to make sure I'm not doing
something really bad by leaving out the dtor. =)

Nope. Only specify them if there is no other object that will "own" the instances of a class.

The good news is that up until shutdown, wxMozilla behaves just like it's
wxWindows counterpart. :slight_smile:

Cool!

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!