Solved

Frame window memory leaks

Posted on 2001-08-16
2
295 Views
Last Modified: 2013-11-20
In case anyone has a quick answer:

When I use CFrameWnd::Create to open a frame window, and then close it via its Close button, why does this lead to unfreed memory allocated in the following areas:

CWnd::CreateObject, CPlex::Create, CPlex::Create, CMapPtrToPtr::InitHashTable, CMapPtrToPtr::InitHashTable, CString::AllocBuffer, <unknown>, CMenu::CreateObject, CMenu::CreateObject


Otherwise, here's a detailed explanation of my problem:

I am trying to track down a memory leak using a test app under VC5 and with the help of BoundsChecker 6.2. After building a debug version of the code using VC5, I run it with BC integrated debugging enabled. It is a simple SDI app with a couple menu options and the following two handlers for them:

void CMainFrame::OnViewNewframe()
{
    CFrameWnd *pframe = new CFrameWnd;
    pframe->Create(NULL, "test frame", WS_OVERLAPPEDWINDOW | WS_VISIBLE);
}

void CMainFrame::OnViewCheckmemory()
{
    static int i = 0;
    if (i == 0)
    {
        OpenMutex(MUTEX_ALL_ACCESS,TRUE,"bogusmutex");
        i++;
        return;
    }
    if (i == 1)
    {
        OpenMutex(MUTEX_ALL_ACCESS,TRUE,"bogusmutex");
        i++;
        return;
    }
    if (i == 2)
    {
        OpenMutex(MUTEX_ALL_ACCESS,TRUE,"bogusmutex");
        i++;
        return;
    }
}

I first select the View|Check Memory option, which causes a deliberate error to be detected by BC so that I can access its Mark Memory option.

I then select the View|New Frame option, which does nothing more than open a simple CFrameWnd by calling its Create member. I then close the frame.

Finally, I select View|Check Memory again to cause another deliberate error so that I can determine all instances of memory allocated but unfreed since I did Mark Memory. This results in the above list.

Anyone know why these leaks are happening and how to get rid of them? TIA.

0
Comment
Question by:Euromuffin
2 Comments
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 75 total points
ID: 6394688
CFrameWnd should clean itself up when its PostNcDestroy handler is called - is this happening - try breakpointing in src\winfrm.cpp


If you want to set the memory marking then why not just set a breakpoint?

If you have bounds checker try upping the options to maximum or custom and set 'report call stack' in the pointer and leak checking category - this will give you a call stack for each leak
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9521234
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: ShaunWilde

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
Expand macro to ask for filename column 8 37
Window placement 17 75
scoreUp challenge 14 57
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now