Solved

Frame window memory leaks

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

24 Experts available now in Live!

Get 1:1 Help Now