Solved

Frame window memory leaks

Posted on 2001-08-16
2
298 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
Folder Comparison 12 55
Whole sheet autoscrub still needed 19 53
move a line in eclipse 3 109
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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