Search

CVSListBox produces memory Leaks by AngusX

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 646445
Opened: 2/23/2011 8:22:36 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
I tried to use a new CVSListBox but I got a lot of memory leaks.
There seems to be more than one problem.

The first leak is in CMFCVisualManager. I managed it by adding a "CMFCVisualManager::DestroyInstance();" in the destructor of my App, but it's an error anyway.

The second is much bigger problem. I could track it down to the following reason:
- OnInitDialog subclasses the Feature Pack controls in a CMFCControlContainer. This creates a new CVSListbox object for the control, creates the buttons AND the tooltips for the buttons.
- After that, DoDataExchange in my App will be called. The DDX_Control uses MY CVSListBox object for the control. When called, it detects, that the object isn't initialized and calls "ReSubclassControl" from "CMFCControlContainer". Up to this point everything is OK. ReSubclassControl detects that the control is already subclassed and deletes the old object, thats OK, too. But the Problem is due to the fact, that the tooltips of the buttons were deleted in "CMFCButton::OnDestroy"! But this function won't be called because I destroy the object but not the window.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Reliability

Steps to reproduce

- Create a new CDialog based Project.
- Add a CVSListBox to the Dialog.
- Add a member Variable for the Listbox (if you add the variable with the class wizard it will produce a "VSListBox mylist;". You must correct this by hand to "CVSListBox mylist;").
- Run The program, show the dialog and close it. There will be some memory leaks.

Product Language

German

Operating System

Windows 7

Operating System Language

Any

Actual results

Memory lealks from CVSListBOx, CMFCVisualManager and CToolTipCtrl.

Expected results

No memory leaks.
File Attachments
0 attachments
Sign in to post a comment.
Posted by AngusX on 2/28/2011 at 10:53 PM
Does "fixed in MFC for the next major release of Visual Studio" mean "fixed in VS 2012" (or whenever the next version is released)? Or is there possibly an earlier fix in the VS 2010 redistributable (I think in MFC100.dll) or / and in VS 2010 SP1?
Posted by Microsoft on 2/28/2011 at 5:28 PM
Hello,

Thanks for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by AngusX on 2/24/2011 at 5:47 AM
I've got a very, very, very nasty workaround (for everyone who has the same problem).

At first place a "CMFCVisualManager::DestroyInstance();" in the destructor of your dialog or, better, of your App. Then you get rid of the allocated CMFCVisualManager which won't be destroyed otherwise.

At next, we must get rid of the awful tooltips from the CVSListBox buttons. The tooltips will be destroyed in "OnDestroy" of the button, but we will resubclass the control and only delete the already allocated CVSListBox object, not destroy the control itself. For this I used all bad things you can do in C++ (unsafe casting). Here are the steps:

- Declare a helper class for CVSListBox:

class DummyListBox : public CVSListBox
{
public:
    void Putzen();
};

void DummyListBox::Putzen()
{
    POSITION pos;

    pos = m_lstButtons.GetHeadPosition();
    while (pos)
    {
        ((DummyButton*)m_lstButtons.GetNext(pos))->Putzen();
    }
}

- Declare a helper class for CMFCButton:

class DummyButton : public CMFCButton
{
public:
    void Putzen();
};

void DummyButton::Putzen()
{
    CTooltipManager::DeleteToolTip(m_pToolTip);
    m_pToolTip = NULL;
}

- Declare a variable bStartUp in your dialog.
- Set the variable to true in the constructor.
- In "DoDataExchange" add "if (!bStartUp)" before the DDX_Control for your CVSListBox control.
- In "OnInitDialog" insert the following three lines AFTER "CDialog::OnInitDialog();":

bStartUp = false;
((DummyListBox*)GetDlgItem("YourListBoxID"))->Putzen();
UpdateData(FALSE);

Hope this helps everybody with the same problem until MS has a solution (I think a new MFC100.dll).
Posted by Microsoft on 2/23/2011 at 10:27 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 2/23/2011 at 9:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.