Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Memory Leaks

Posted on 1999-08-21
1
Medium Priority
?
450 Views
Last Modified: 2013-11-20
I have a dialog box with two exit options.

In the first, I free all memory taken by my operations, then call CDialog::OnOk(). It passes smoothly and with no problems.

In the second, I free all memory taken, just as above and with the same commands, and then call exit(0). I need this because this is a 2nd-level dialog and I want to give the user the opportunity to quit the application immediately, without having to return him to the calling 1st-level dialog.

However, this exit(0) causes a memory leak: nothing serious, less than 100 bytes but still it's a nuisance. So, the question is actually two questions:

1) What does CDialog::OnOk() do to free memory that exit(0) doesn't do?

2) Is there any Windows-style function to replace the DOS-style exit(0) function?
0
Comment
Question by:Lescha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
vachooho earned 80 total points
ID: 1314591
You can not call exit() within your MFC application without getting in trouble.

CDIalog's destructor is doing all the work need to free up memory used etc. Exit() will terminate the program immediately without any kind of work (let's say so but actualy exit() is doing some work but not regarding MFC objects because it know nothing about them!).


You can close your application this way:
this->PostMessage(WM_CLOSE);
pFirstLevelDialog->PostMessage(WM_CLOSE);
pMainDialog->PostMEssage(WM_CLOSE);

if you have CMainFrame derived main window i.e. Doc.View model tehn you  can use this
AfxGetMainWnd()->SendMessage(WM_COMMAND, (WPARAM)ID_APP_EXIT);
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question