Where is the dtor for _wxString?

Questions about wxWidgets running on MS.NET, mono or Portable.NET ? Ask it here !
Post Reply
AHUser
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Oct 28, 2004 11:40 pm

Where is the dtor for _wxString?

Post by AHUser » Thu Oct 28, 2004 11:44 pm

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;
}

Bryan Bulten
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Oct 28, 2004 11:45 pm
Location: Victoria, BC, Canada
Contact:

Post by Bryan Bulten » Thu Oct 28, 2004 11:59 pm

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.

AHUser
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Oct 28, 2004 11:40 pm

Post by AHUser » Sat Oct 30, 2004 8:23 am

(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.

Bryan Bulten
In need of some credit
In need of some credit
Posts: 8
Joined: Thu Oct 28, 2004 11:45 pm
Location: Victoria, BC, Canada
Contact:

Post by Bryan Bulten » Tue Nov 02, 2004 5:46 am

I see your point now.

Fixed in CVS.

Post Reply