Solved

Frame window memory leaks

Posted on 2001-08-16
2
297 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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