X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ea57084d103187771c0306a6e1684e32244d6101..5b6ec9803a058368a1b240a22d444c7301c5715a:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index e67b404eed..a9fb77fdd2 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -50,10 +50,15 @@ #include #endif -// use debug CRT functions for memory leak detections in VC++ -/* Here we go again commenting it out. PLEASE don't - * uncomment this again. -#if defined(__WXDEBUG__) && defined(_MSC_VER) +// use debug CRT functions for memory leak detections in VC++ if we're not +// using wxWindows own methods +#if defined(__WXDEBUG__) && defined(_MSC_VER) && !wxUSE_GLOBAL_MEMORY_OPERATORS && !defined(__NO_VC_CRTDBG__) + #define wxUSE_VC_CRTDBG +#else + #undef wxUSE_VC_CRTDBG +#endif + +#ifdef wxUSE_VC_CRTDBG // VC++ uses this macro as debug/release mode indicator #ifndef _DEBUG #define _DEBUG @@ -61,7 +66,6 @@ #include #endif -*/ extern char *wxBuffer; extern char *wxOsVersion; @@ -115,26 +119,12 @@ bool wxApp::Initialize() { wxBuffer = new char[1500]; -/* PLEASE don't uncomment this again. IT DOESN'T WORK when building - * using the makefile. - #if defined(__WXDEBUG__) && defined(_MSC_VER) + #ifdef wxUSE_VC_CRTDBG // do check for memory leaks on program exit // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free // deallocated memory which may be used to simulate low-memory condition) _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF); #endif // debug build under MS VC++ -*/ - - #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - #if defined(_WINDLL) - streambuf* sBuf = NULL; - #else // EXE - streambuf* sBuf = new wxDebugStreamBuf; - #endif // DLL - - ostream* oStr = new ostream(sBuf) ; - wxDebugContext::SetStream(oStr, sBuf); - #endif // wxUSE_MEMORY_TRACING wxClassInfo::InitializeClasses(); @@ -494,6 +484,23 @@ void wxApp::CleanUp() wxClassInfo::CleanUpClasses(); + delete wxTheApp; + wxTheApp = NULL; + +#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT + // At this point we want to check if there are any memory + // blocks that aren't part of the wxDebugContext itself, + // as a special case. Then when dumping we need to ignore + // wxDebugContext, too. + if (wxDebugContext::CountObjectsLeft() > 0) + { + wxLogDebug("There were memory leaks."); + wxDebugContext::Dump(); + wxDebugContext::PrintStatistics(); + } +// wxDebugContext::SetStream(NULL, NULL); +#endif + // do it as the very last thing because everything else can log messages wxLog::DontCreateOnDemand(); delete wxLog::SetActiveTarget(NULL); @@ -568,24 +575,14 @@ int wxEntry(WXHINSTANCE hInstance, } wxTheApp->OnExit(); - wxApp::CleanUp(); - delete wxTheApp; - wxTheApp = NULL; + // flush the logged messages if any + wxLog *pLog = wxLog::GetActiveTarget(); + if ( pLog != NULL && pLog->HasPendingMessages() ) + pLog->Flush(); -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // At this point we want to check if there are any memory - // blocks that aren't part of the wxDebugContext itself, - // as a special case. Then when dumping we need to ignore - // wxDebugContext, too. - if (wxDebugContext::CountObjectsLeft() > 0) - { - wxTrace("There were memory leaks.\n"); - wxDebugContext::Dump(); - wxDebugContext::PrintStatistics(); - } - wxDebugContext::SetStream(NULL, NULL); -#endif + + wxApp::CleanUp(); return retValue; #ifndef __WXDEBUG__ // catch exceptions only in release build