Solved

Frame window memory leaks

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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