[ wxwindows-Bugs-1729058 ] Memory Leak in AuiNotebook when AddPage is called

SourceForge.net noreply at sourceforge.net
Fri Jun 8 02:26:36 PDT 2007


Bugs item #1729058, was opened at 2007-05-31 18:52
Message generated for change (Comment added) made by tibosoft
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1729058&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: AUI
Group: Must fix
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: jmgl (jmgl)
Assigned to: Benjamin I. Williams (biwillia76)
Summary: Memory Leak in AuiNotebook when AddPage is called

Initial Comment:
Build: Widgets 2.8.3 built with MSVC++8 running on 64bit Windows XP.

When wxAuiNotebook::AddPage is called for the first time, it calls wxAuiNotebook::GetActiveTabCtrl: when GetActiveTabCtrl is called for the first time, a new wxTabFrame is created, line 2922:
 wxTabFrame* tabframe = new wxTabFrame;

Although tabframe gets added to m_mgr further into the GetActiveTabCtrl implementation, its destructor doesn't appear to ever get called. 

I verified this behaviour with the auidemo sample, and in my own code. Evidence of the leak is given in visual studio outputs:
Detected memory leaks!
Dumping objects ->
{12065} normal block at 0x023C99D8, 24 bytes long.
 Data: <p #             > 70 95 23 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{12064} normal block at 0x023C9830, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
The program '[3444] auidemo.exe: Native' has exited with code 0 (0x0).

I ran the code within Software Verification's "Memory Validator" tool and it points to two leaks relating to the creation of the wxTabFrame above: the 364 bytes relates to wxTabFrame, while the 24 bytes appears to be the critical section "m_eventsLocker" created when wxTabFrame is created, i.e. line 1011 of event.cpp:
wxEvtHandler::wxEvtHandler()
{
    m_nextHandler = (wxEvtHandler *) NULL;
    m_previousHandler = (wxEvtHandler *) NULL;
    m_enabled = true;
    m_dynamicEvents = (wxList *) NULL;
    m_pendingEvents = (wxList *) NULL;
#if wxUSE_THREADS
#  if !defined(__VISAGECPP__)
    m_eventsLocker = new wxCriticalSection;
#  endif
#endif
    
    // no client data (yet)
    m_clientData = NULL;
    m_clientDataType = wxClientData_None;
}

A sample callstack below shows this relationship
>MyApp.exe!wxEvtHandler::wxEvtHandler()  Line 1011	C++
 MyApp.exe!wxWindowBase::wxWindowBase()  Line 130 + 0x41 bytes	C++
 MyApp.exe!wxWindow::wxWindow()  Line 42 + 0x35 bytes	C++
 MyApp.exe!wxTabFrame::wxTabFrame()  Line 2221 + 0x44 bytes	C++
 MyApp.exe!wxAuiNotebook::GetActiveTabCtrl()  Line 2922 + 0x25 bytes	C++


I also stubbed a destructor in the implementation of wxTabFrame and put a break-point on it - and it definitely didn't get called.

Finally I used the feature in auidemo to generate multiple notebooks (i.e. through the View > Create Notebook menu) and got multiple instances of the same leak
Detected memory leaks!
Dumping objects ->
{32742} normal block at 0x03033EE8, 24 bytes long.
 Data: <X|%             > 58 7C 25 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{32741} normal block at 0x03033D40, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
{28217} normal block at 0x0244B4F8, 24 bytes long.
 Data: <X %             > 58 1B 25 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{28216} normal block at 0x0244B350, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
{23437} normal block at 0x02422B00, 24 bytes long.
 Data: <  $             > B8 B0 24 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{23436} normal block at 0x02422958, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
{19077} normal block at 0x023FC288, 24 bytes long.
 Data: < D$             > A0 44 24 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{19076} normal block at 0x023FC0E0, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
{12077} normal block at 0x023C99D8, 24 bytes long.
 Data: <p #             > 70 95 23 00 FF FF FF FF 00 00 00 00 00 00 00 00 
{12076} normal block at 0x023C9830, 364 bytes long.
 Data: <Lgq             > 4C 67 71 00 00 00 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
The program '[3160] auidemo.exe: Native' has exited with code 0 (0x0).

Best regards,
JMGL

----------------------------------------------------------------------

Comment By: tibo (tibosoft)
Date: 2007-06-08 11:26

Message:
Logged In: YES 
user_id=1227974
Originator: NO

I just came across this "bug" (feature?) and noticed that closing all tabs
prior to application shutdown (e.g. just before wxAuiManager::UnInit())
does not create a memory leak. Maybe the programmer is supposed to call
wxNotebook::RemovePage() for all pages before the app shuts down ? 
But it seems that this could be done in the notebook's destructor.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1729058&group_id=9863




More information about the wx-dev mailing list