Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Not calling ExitInstance

168 views
Skip to first unread message

Rob C

unread,
Nov 7, 2003, 1:11:31 AM11/7/03
to
I am using MFC in Visual Studio .NET 2003. When
investigating a memory leak, I discovered that my CWinApp
overridden ExitInstance method was not getting called at
the end of the execution. I know it did at one time and
then only thing significant that I did was move my project
from Visual Studio V6 to VS .NET 2003.

I set a breakpoint in the ExitInstance method and it never
breaks.

This is my definition in my CPP file:

int CCMSDesktopApp::ExitInstance()
{
// Release COM
CoUninitialize();

if (m_pListMgr)
{
delete m_pListMgr;
}

return CWinApp::ExitInstance();

}

In my h file I declare:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCMSDesktopApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL


Any ideas on what might be happening here?

Thanks,

-Rob

Fenster

unread,
Nov 7, 2003, 2:43:13 AM11/7/03
to

Is the application dialog-based? They always (usually?) exit directly
from InitInstance() and I have a vague recollection that ExitInstance()
isn't called if FALSE is returned from InitInstance().


In message <089301c3a4f5$fd2307a0$a101...@phx.gbl>, Rob C
<anon...@discussions.microsoft.com> writes

--
Fenster

Joseph M. Newcomer

unread,
Nov 7, 2003, 11:42:40 AM11/7/03
to
You are correct that they exit directly from InitInstance. However, if you check
thrdcore.cpp (near line 116 in VS6 version) you will see that ExitInstance is always
called, even when InitInstance returns FALSE.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Rob C

unread,
Nov 8, 2003, 10:50:52 PM11/8/03
to
The app is an SDI app. The strange thing is that when I
build the app in VC V6, it calls ExitInstance. When I
build it in VS .NET, it does not call ExitInstance. It is
the same exact source code for both.

Regards,

-Rob

>.
>

Joseph M. Newcomer

unread,
Nov 9, 2003, 9:35:21 PM11/9/03
to
Then perhaps Microsoft changed the behavior. This is, of course, trivial to determine:
just read the MFC source code.
joe

Joseph M. Newcomer [MVP]

Alexander Grigoriev

unread,
Nov 10, 2003, 12:50:09 AM11/10/03
to
ExitInstance is called in CWinThread::PumpMessage. This is the only point of
normal return from the message loop.
Another call is in CFrameWnd::OnEndSession.
You're not calling exit() anywhere by any chance?

"Rob C" <anon...@discussions.microsoft.com> wrote in message
news:038201c3a674$ab9287f0$a301...@phx.gbl...

0 new messages