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

deleting CMultiDocTemplate object

374 views
Skip to first unread message

jasmine

unread,
Mar 18, 2002, 12:35:57 AM3/18/02
to
I have created some "new" "CMultiDocTemplate" objects in the "InitInstance"
of my application. When I try to "delete" those objects in my application
override of "ExitInstance" it gives ASSERT error in CWinApp::ExitInstance().

How can I delete those objects. because I see memory leak if I don't delete
them.

Thanks in advance,

Jas


Scot T Brennecke

unread,
Mar 18, 2002, 1:43:37 AM3/18/02
to
Jas,
What is reporting the memory leaks to you? You should never have to delete the
doc templates yourself, as long as you called AddDocTemplate in InitInstance (I
assume you did). The doc manager cleans up the templates when the app shuts
down. What version of MFC do you have? I don't see a place in my version of
the ExitInstance that an assertion would fail like that.

jasmine

unread,
Mar 18, 2002, 4:48:11 AM3/18/02
to
Hi Scot!

memory leak reports:

"{83} client block at 0x00302E00, subtype 0, 144 bytes long.a
CMultiDocTemplate object at 00302E00, 144 bytes long"

I am using MFC version 6.

Actually ExitInstance in CWinApp calls SaveStdProfileSettings where
ASSERT_VALID(this) get called.

Thanks,
Jas


Scot T Brennecke

unread,
Mar 18, 2002, 7:08:19 PM3/18/02
to
Jas,
Was anything else reported as leaked, besides the doc templates? Sometimes
it's a larger container that isn't destroyed, and when you finally delete it,
the container will destroy the objects inside it. You did call AddDocTemplate
in the InitInstance, right?

jasmine

unread,
Mar 18, 2002, 8:47:23 PM3/18/02
to
Scot,


> Was anything else reported as leaked, besides the doc templates?

No! nothing else has reported as leaked.

> You did call AddDocTemplate in the InitInstance, right?

Yes! I did call AddDocTemplate.


The difference between my application and MFC AppWizard generated
application is that I declared CMultiDocTemplate* object as my application's
MEMBER variable :

m_pMyTemplate = new CMultiDocTemplate(...);
AddDocTemplate(m_pMyTemplate);

I don't know if that is the source of problem. But I need to do that because
I need to have access to this member from somewhere else in my program.

Jas.


Scot T Brennecke

unread,
Mar 19, 2002, 1:29:09 AM3/19/02
to
No. That should not be a problem. However, we still need to isolate why the
normal process of deleting all the doc templates is not working. I suspect
there must be something else "unorthodox" you have done that's short-circuiting
the normal exit sequence. It's not necessarily that you've done something
"wrong", but perhaps you have only "half done" something non-standard.

Have you identified the standard MFC code that deletes the doc templates? Put a
breakpoint in there, and step through to discover why your object is not getting
deleted properly. If it doesn't hit your breakpoint, then we need to find out
why.

Herbert Thomas

unread,
Mar 19, 2002, 9:08:15 AM3/19/02
to
MSDN-Sample: CHKBOOK generates two instances of CMultiDocTemplate.

Close the app and debug the destructor CDocManager::~CDocManager() in file
docmgr.cpp.
Count how often the while-loop is performed and count how often you called
AddDocTemplate.
The difference should be zero if pTemplate->m_bAutoDelete is TRUE;.


0 new messages