Support delayed destruction in console applications too.\n\nThis only works if there is a running event loop but if there is one, we can have the same kind of problems with non-GUI objects such as sockets in console applications as we have with windows in GUI ones, so we must support this (see #10989).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61488 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-07-21 14:16:44 +00:00
parent 2388960a08
commit 3185abc278
8 changed files with 203 additions and 129 deletions

View File

@@ -841,12 +841,6 @@ wxSocketBase::wxSocketBase(wxSocketFlags flags, wxSocketType type)
wxSocketBase::~wxSocketBase()
{
// Just in case the app called Destroy() *and* then deleted the socket
// immediately: don't leave dangling pointers.
wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
if ( traits )
traits->RemoveFromPendingDelete(this);
// Shutdown and close the socket
if (!m_beingDeleted)
Close();
@@ -855,8 +849,7 @@ wxSocketBase::~wxSocketBase()
delete m_impl;
// Free the pushback buffer
if (m_unread)
free(m_unread);
free(m_unread);
}
bool wxSocketBase::Destroy()
@@ -872,14 +865,13 @@ bool wxSocketBase::Destroy()
// Suppress events from now on
Notify(false);
// schedule this object for deletion
wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
if ( traits )
// Schedule this object for deletion instead of destroying it right now if
// possible as we may have other events pending for it
if ( wxTheApp )
{
// let the traits object decide what to do with us
traits->ScheduleForDestroy(this);
wxTheApp->ScheduleForDestruction(this);
}
else // no app or no traits
else // no app
{
// in wxBase we might have no app object at all, don't leak memory
delete this;