Missing destructor calls on exit

Sorry if this is well covered ground, but many of the tactics I tried
to employ from other threads didn't pan out (and most importantly
allow me to understand _why_ this is happening).

I have a doc/view mdi app.  My runtime library is multi-threaded debug
DLL.  On exit of the application (via file..exit or the X button), I
get a bunch of memory leaks.  Some from a modeless dialog (whose
destructor is not called), the CMainFrame itself (all 2K), the
CDocManager, CMultiDocTemplate, and a CCmdTarget (these are created by
the CWinApp I believe).  A breakpoint gets hit in my CMainFrame (which
happens to be the parent of the modeless dialog) destructor, but for
some reason I still have that 2K of memory lost.  It looks like the
bulk of the memory allocated by the app is not getting put away, all
that stuff in InitInstance().  As for the modeless dialog, perhaps
that's a separate issue.

For the MainFrame, DocManager, etc, I have no idea.  This is so high
up in the chain I don't know how it's getting left out.  I didn't
override any functions for WinApp involving destruction, just ones
like FILE_SAVE, FILE_OPEN, etc.

As for the modeless dialog, I read in another thread that the
"preferred" way to get rid of a modeless dialog gracefully was to
override OnNcDestroy and call "delete this", in conjuction with
ON_WM_CLOSE and call "DestroyWindow".  This, however, resulted in a
crash via RtlValidateHeap(x,x).  I suspect, however, that is may be
because the modeless dialog uses a custom object, a PropTree, which
happens to have its code in a DLL I link to.  Because this DLL is
separate from the main code, is it living in another heap and I can't
get rid of it from the application?

I know these are a lot of questions, and the solution may seem
obvious, but I've been beating my head and don't know what's expected
or normal in these situations.  LIke I said, the solution doesn't
matter to me so much as understanding why this is happening in the
first place.  (Probably something I messed up/overrode.)  Much thanks
in advance for the help.
0
ventudg (16)
4/15/2004 11:38:40 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
536 Views

Similar Articles

[PageSpeed] 46

as you have a lot of questions, would you think that'll be possible to send over your project(ovidiu7676@yahoo.com)?
0
anonymous (74722)
4/15/2004 12:21:14 PM
"HeroOfSpielburg" <ventudg@hotmail.com> wrote in message
news:ff4d2e3a.0404150338.333de6e6@posting.google.com...
> Sorry if this is well covered ground, but many of the tactics I tried
> to employ from other threads didn't pan out (and most importantly
> allow me to understand _why_ this is happening).
>
> I have a doc/view mdi app.  My runtime library is multi-threaded debug
> DLL.  On exit of the application (via file..exit or the X button), I
> get a bunch of memory leaks.  Some from a modeless dialog (whose
> destructor is not called), the CMainFrame itself (all 2K), the
> CDocManager, CMultiDocTemplate, and a CCmdTarget (these are created by
> the CWinApp I believe).  A breakpoint gets hit in my CMainFrame (which
> happens to be the parent of the modeless dialog) destructor, but for
> some reason I still have that 2K of memory lost.  It looks like the
> bulk of the memory allocated by the app is not getting put away, all
> that stuff in InitInstance().  As for the modeless dialog, perhaps
> that's a separate issue.

    Something could be throwing an exception in the destructor, which might
well abort the destruction process but still allow your program to exit.
Try steping through the destructor to find what goes wrong.

> As for the modeless dialog, I read in another thread that the
> "preferred" way to get rid of a modeless dialog gracefully was to
> override OnNcDestroy and call "delete this", in conjuction with
> ON_WM_CLOSE and call "DestroyWindow".  This, however, resulted in a
> crash via RtlValidateHeap(x,x).  I suspect, however, that is may be
> because the modeless dialog uses a custom object, a PropTree, which
> happens to have its code in a DLL I link to.  Because this DLL is
> separate from the main code, is it living in another heap and I can't
> get rid of it from the application?

    Having objects delete themselves like that is a dangerous idea.  In
order for it to work, you need to provide some means of seting all the
pointers to the object to NULL in the objects destructor, otherwise you end
up with wild pointers to where the object was.  It's usually simpler to
delete the object from code that has easy access to the pointers.  The
documents and views that MFC uses have a bit of machinery to get away with
the auto delete technique.
    The other dll might or might not have a seperate heap.  If it does have
a seperate heap, it should provide functions to deallocate the prop tree
safely.  I'd look at your documentation to see how the PropTree object
should be deallocated.

> I know these are a lot of questions, and the solution may seem
> obvious, but I've been beating my head and don't know what's expected
> or normal in these situations.  LIke I said, the solution doesn't
> matter to me so much as understanding why this is happening in the
> first place.  (Probably something I messed up/overrode.)  Much thanks
> in advance for the help.

    You're welcome.  I hope this helps.

                                        Nathan Holt




0
nathanh (83)
4/19/2004 3:46:31 PM
Reply:

Similar Artilces:

Outlook Connector crashes Outlook 2003 on exit
After installing Outlook Connector, Outlook 2003 keeps crashing on exit. Is there some way to fix this? Here is the stack trace: (21c.1478): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. eax=002409b8 ebx=00000000 ecx=feeefeee edx=00000000 esi=0318d6cc edi=00000000 eip=0312a91f esp=0013f92c ebp=0013f934 iopl=0 nv up ei ng nz na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010282 *** ERROR: Symbol file could not be found. Defaulted to export symbols f...

Money 2006 Exit without Command
I am running Money 2006. Today as I was entering transactions, it exited without command. No message like a normal shutdown. When I tried starting it again, it would come up with most of the opening screen but would suddenly disappear without a trace. I am running XP with all the latest updates. I rebooted and tried again with the same result. Any suggestions? Regards Robert Additional things that I have tried since posting my first message: 1. Downloaded date file repair tool and ran it against my data file - no change in operation. 2. Disabled Norton Antivirus - no change i...

Maximize, minimize and close missing
This is a multi-part message in MIME format. ------=_NextPart_000_0052_01C4C323.D2A559E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am not sure why, but suddenly on certain files - the maximize, = minimize and close button is missing. There doesn't seem to be any = rhyme or reason for it. I am running excel 2003. Thanks Karen S ------=_NextPart_000_0052_01C4C323.D2A559E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Tr...

Do WIA scan without calling IWiaDevMgr->DeviceDlg()
I am trying to do a wia scan using the IWiaDevMgr, IWiaItem and IWiaDataTransfer Created the IWiaDevMgr as in the following code CComPtr<IWiaDevMgr> pWiaDevMgr hr = pWiaDevMgr.CoCreateInstance(CLSID_WiaDevMgr); then call the CreateDevice on that object with the correct device id hr=pWiaDevMgr->CreateDevice(str,&pItemRoot); and then i call DeviceDlg on the pItemRoot CComPtrArray<IWiaItem> ppIWiaItem; hr = pItemRoot->DeviceDlg( hWndParent, lFlags, lIntent, &ppIWiaItem.Count(), &ppIWiaItem ); make IWiaDataTransfer using the ...

macro to exit design mode
I am creating protected worksheets for users. When some users open them, their Excel is already in Design Mode. I need code to 'exit' design mode automatically. Can anyone advise please? -- cm see if this helps: Sub ExitDesignMode() With CommandBars("Exit Design Mode").Controls(1) If .State = msoButtonDown Then .Execute End With End Sub -- jb "cm" wrote: > I am creating protected worksheets for users. When some users open them, > their Excel is already in Design Mode. > > I need code to 'exit&#...

Forwarded Messages In Outlook Missing
Hi Everyone I have an odd problem. When I forward a message from my sent items the person receives it but I don't get a copy of the forwarded message in my sent items. Please Advise.... best regards Marco www.classactinsurance.com go to Tools > options > email options > advanced email options > and check save forwarded messages "Marco" <marcodejulio@gmail.com> wrote in message news:1124297942.705533.125430@o13g2000cwo.googlegroups.com... > Hi Everyone > I have an odd problem. When I forward a message from my sent items the > person receives it bu...

Winfax 10 causes an error on Exit of Outlook 2003!!
Hi all Just installed Winfax 10 and since doing so, everytime I exit Outlook 2003 I get an error "Microsoft Office Outllok has encountered a problem and needs to close, We are sorry for this inconvenience." I did view the report prepared for sending to MS and there was mention of the Winfax plugin causing the problem. Anyone know of a workaround or perhaps I need to dump Winfax! Regards John Have you checked with Symantec yet to see if they have managed to get WinFax 10 to work with Outlook 2003? It usually takes them several months to bring WinFax up to speed, if they ever ...

OnPaint not being called!
I have a class derived from CWnd in which I override OnPaint() and OnDestroy(). They're never called, even though I paint my window, and destroy it. Why not? (This is on Windows CE - make any difference?) -- Thanks, Brian Toothill Did you attach it to a variable of the correct subclass type? A window will not be called unless there has been a binding to a variable; that's how the association to the MESSAGE_MAP is made. joe On Thu, 18 Sep 2003 14:45:54 +0100, "Brian Toothill" <.> wrote: >I have a class derived from CWnd in which I override OnPaint() and ...

Some mails missing
Hi, I 'm using exchange 5.5 with sp3 and one of my user mailbox reached its limit and after he has done some houskeeping he's able to receive and sending out mails. But the problem now is he complained that he did not received some external emails during his mailbox was full. How long does the server keep the inbound mail before deleting them or is there a way to keep the messages longer on the server? It sounds like you had the limit set for "Prohibit Send and Receive" - if so the senders would receive an NDR stating the mailbox was over the limit and the mail is go...

Is it possible to call reporting Services from our internet web si
Is it possible to call reporting Services from our internet web site? The website and reporting server are on different domains. What i am looking is when user clicks on the link of our web site to see reports he needs to be prompted with windows credentials. This is happening now on our web site and when he/she gives his/her credentials the user should be successfully taken to the home page of reporting services. But instead of this we are getting "The page can not be dispalyed error". What needs to be done to fix this. Thank You. ...

How to get userform Cancel button to invoke Exit Sub in calling macro?
I have a userform that is called from inside a sub in a module of a workbook. In order to keep most of the code inside the module, the userform only sets variables in the sub. Here is the code in the sub: 'create and initialize variables Dim Bkp,XSub as Boolean Dim BkpSfx as String Bkp = True XSub = False 'call options box BackupOptionsBox.Show 'Set main subroutine variables Bkp = BackupOptionsBox.YesOption BkpSfx = "_" & BackupOptionsBox.SfxBox.Value ...

ExitThread hazardous to your destructors
Please comment on the following truly HORRIBLE glitch that I discovered Originally I stumbled across the problem working on a GUI application with VC++ 7.0 in a Windows 2000 environment. This morning, I reproduced the problem at home working with VC++ 6.0 under Windows 98 thread_1 explicitly calls ExitThread. The TestObject destructor fails to be called thread_2 relies on ExitThread being called implicitly when the thread returns Everything behaves the way it should The MSDN Library state "ExitThread is the preferred method of exiting a thread. http://msdn.microsoft.com/library/defaul...

Personal options OK button Missing
We are running 1.2 and on some machine(not all) - the OK button is missing when you go to Tools/Options. Has anybody seen this behaviour before? ...

Installation--broken or missing win.ini file
I have a new Dell XPS Studio 13 with Windows 7. I purchased Outlook 2007 separately. It worked fine for a month or so, then for no discernible reason I got a message "can't open Outlook Window." I looked for help online, but couldn't find anything on this for Windows 7. So I uninstalled and tried to re-install. However, during the re-install, I got a message that there is a missing or broken win.ini file, and the installation won't work. Any help appreciated. Please note that I am not a techie, so please keep responses as simple as possible (and ple...

Conference call coordination
Help! I need a template or form of some kind to use when setting up conference calls. I have many callers, many possible times, many time zones involved. I'd like something I could fill in for each person as they tell me when they are available and when they are NOT available. Then I could see what the possible times are for the most participants. Any suggestions? Hi why not use a tool such as Outlook, Notes, etc. for this?? -- Regards Frank Kabel Frankfurt, Germany Duke secretary wrote: > Help! I need a template or form of some kind to use when setting up > conference...

Saved text is missing from 2003 word document
When opening a saved 2003 word document the text is missing. See if the text has been inadvertently formatted as hidden or in white color. -- Stefan Blom Microsoft Word MVP "lpaul" <lpaul@discussions.microsoft.com> wrote in message news:ED677478-49D2-4461-AE94-8EFBFF2CCAB9@microsoft.com... > When opening a saved 2003 word document the text is missing. ...

Call up computer name
[Excel 2003] Is there a way to retrieve the computer identity/name and display it in a listbox on a userform? regards, Roger uName =3D Environ("computername") Me.ListBox1.AddItem uName On Dec 3, 9:30=A0am, Roger on Excel <RogeronEx...@discussions.microsoft.com> wrote: > [Excel 2003] > > Is there a way to retrieve the computer identity/name and display it in a > listbox on a userform? > > regards, > > Roger Thanks - works nicely Roger "muddan madhu" wrote: > > uName = Environ("computern...

debugging missing images in a CTreeCtrl
Hello, I am having some difficulty trying to debug some missing images in a CTreeCtrl. Essentially, I subclass CDialog and have a CTreeCtrl and CImageList as data members. The CTreeCtrl is supposed to be an expandable tree with each item containing a standard checkbox and a 16x16 solid icon. The problem is that the icons are not showing up at all. I'm wondering where is a good point to start debugging the missing icon images? Things I have verified: 1. The image list is valid and is set as the TVSIL_NORMAL image list for the CTreeCtrl. 2. The bitmaps within the image list are valid (I o...

Excel pivot tbl
Brand new laptop w/Windows XP. Has Office 97 installed (first), than complete install of Office XP(second). Than install of PTSfull.exe (pivot table services that come w/ sql server analysis services service pack 2). Go to data manu - PivotTable and Pivot Chart report - External data source/Pivot table - Get Data - OLAP cubes - new data source - select an olap provider for the database you want to access - blank dropdown (no Microsoft OLEDB Provider for OLAP Services or Microsoft OLEDB Provider for OLAP Services 8.0). Tried removing Office 97 & Office XP than installing PTS - sa...

Office 2004 Update 11.2.5
Hi, Just a cautionary tale. I updated office last night with the 11.2.5 patch. Now Entourage, Powerpoint and Excel are missing. Spotlight can't find them and they are not in the trash. They have vanished from the /Applications/Microsoft Office 2004/ folder. Word is still there and works. I guess I will just have to re-install from the disc. Don't know what caused it the log only documents things written to the disk not erased. Matthew OS X 10.4.5 512 DDR SDRAM 1.42 GHz PPC G4 Hi Marcel - Are you sure it was the 11.2.*5* update that caused the problem, not 11.2.*6* ? That is mo...

Pre-loaded Excel 2007 missing "Analysis ToolPak"
Help! My PC came pre-loaded with Excel 2007; however, I see that "Analysis ToolPak" is inactive in the listed Options. I don't have the CDs for MicroSoft Office or Excel with me (I'm 2000 miles from home), so how do I find and download "Analysis Toolpak"? I need this for my MBA stats class. hi is it listed in the addins dailog. if so all you need to do is check it and its installed. if it doesn't appear on the list then you have a problem. since it's included with excel, MS never made the toolpak available for download.... that i know of. y...

Missing status bar in Microsoft word 2007
I dont know how my status bar which is at the bottom of the document is missing. It is microsoft office 2007. Can somebody help me? How do i recover it? Click on the Maximize button (the one to the left of the Red/White X button at the top right of the screen. Maybe that button had been clicked when it was in its "Restore Down" mode and then the screen was manually sized and moved so that the status bar was below the bottom of the screen. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis...

navigation buttons missing
In my subform I have navigation buttons set to yes but when the form is displayed the navigation buttons are not there. any ideas? -- deb "deb" <deb@discussions.microsoft.com> wrote in message news:BC539484-6057-49B6-BCFD-D887968CCD5C@microsoft.com... > In my subform I have navigation buttons set to yes but when the form is > displayed the navigation buttons are not there. > > any ideas? > -- > deb Sounds like the sub form control is a bit to short. See what happens if you allow scrollbars on the control. -- Bill Mosca, Microso...

Reply/forward arrows missing
We are using Outlook 2002 connected to an Exchange 2000 server. Some users are having a problem where Outlook isn't adding the purple or red arrows to a message after the message has been replied to or forwarded. Makes it hard to tell if an action has been taken on a message. I couldn't find any fixes out there so I'm hoping for some help. Both users who reported this problem have Blackberries and are running the Blackberry Desktop software on their computers. That seems to be the only unique thing. ...

Service Call Escalations
Hi, I am trying to get service call escalations to work so that an email is sent when an escalation is done. Please help with the steps required. I am using the vs10 fabrikam database. To date I have: 1. Setup a service call escalation - from status Entered to Dispatched assigned to technician NEIL. This technician has been setup to use service the items found under the equipment configuration for the equiment piece on the service call. The technician also has a schedule of 8am-5pm each day. An email address has been setup for this technician. 2. Created a service call and assigned it to...