Page 1 of 1

Where is the dtor for _wxString?

Posted: Thu Oct 28, 2004 11:44 pm
by AHUser
The _wxString (helper) class does not have a dtor C function.

Code: Select all

extern "C" WXEXPORT
void wxString_dtor(wxString* self)
{
    if (self)
	delete self;
}

Posted: Thu Oct 28, 2004 11:59 pm
by Bryan Bulten
wxString inherits from wx.Object, which implements Dispose(). When the C# instance of wxString is cleaned up by the garbage collector, this method is called, which in turn calls wxObject_dtor().

Since the wxString destructor is virtual, wxObject_dtor() will call wxString's destructor, and the memory used is cleaned up.

This way may seem more confusing, but lets classes derived from wx.Object be deallocated automattically once they are not in use.

Posted: Sat Oct 30, 2004 8:23 am
by AHUser
(code extracts from wxWidgets 2.5.2)

Code: Select all

class WXDLLIMPEXP_BASE wxString : public wxStringBase {...}
class WXDLLIMPEXP_BASE wxStringBase {...}
And where does it inherit from wxObject?

Code: Select all

    // dtor is not virtual, this class must not be inherited from!
  ~wxStringBase()
And wxString does not implement an own dtor so it uses the static one from wxStringBase.

And where is the virtual dtor?

I think the invocation of the virtual wxObject dtor is subject to access violations.

Posted: Tue Nov 02, 2004 5:46 am
by Bryan Bulten
I see your point now.

Fixed in CVS.