[mapguide-internals] Found at least one memory leaks in
Mapguide API
Bruno Scott
bscott at geomapgis.com
Wed Jul 8 04:20:50 EDT 2009
I found the big one, but i will need some help to fix it.
Let me explain what is happening
I will describe the problem with the m_toolbar member but the same problem
apply to m_taskPane and m_contextMenu
There is a relationship between
m_toolbar
m_commands
m_cmdWidgets
m_toolbar contains a collection of MgWebWidget
m_commands is a collection of MgWebCommand
m_cmdWidgets is a map of MgWebCommandWidget
MgWebCommandWidget is derived from MgWebWidget plus a MgWebCommand
After the first step for parsing a weblayout
- m_commands contains all MgWebCommand with refcount = 1
- m_toolbar contains all MgWebWidget with refcount = 1
- m_cmdWidgets contains all MgWebCommandWidget with refCount = 1 and
MgWebCommand = null
The last step is to
- loop on each MgWebCommandWidget of the m_cmdWidgets
- find the MgWebCommand in the m_commands
- Copy this MgWebCommand into the MgWebCommandWidget (MgWebCommand
refcount becomes 2)
- Finally clear the m_cmdWidgets
When Disposing the WebLayout
m_commands will be also disposed , this set all MgWebCommand refcount to 1
m_cmdWidgets is already cleared
and when m_toolbar is disposed it's the MgWebWidget destructor that is
actually called, leaving the underneath MgWebCommand not disposed.
There is many ways to fixe this Leak
First Idea
this is the actual code that leaks
for( all items in m_cmdWidgets )
{
...
Ptr<MgWebCommand> cmd = m_commands->GetItem(cmdName);
widget->SetCommand(cmd);
}
m_cmdWidgets.clear();
It's the GetItem that increment the refCount, so we could decrease it
for( all items in m_cmdWidgets )
{
...
Ptr<MgWebCommand> cmd = m_commands->GetItem(cmdName);
cmd->RemRef();
widget->SetCommand(cmd);
}
it's simple but not a very clean solution
Second idea
the m_toolbar member could be a MgWebCommandWidgetCollection instead of a
MgWebWidgetCollection
So the destruction of the m_toobar would fire the desctructions of all
underneath WebCommand.
This would require more work as we need to create a new class
(MgWebCommandWidgetCollection )
There is probably other way for fixing this.
Bruno
--
View this message in context: http://n2.nabble.com/Found-at-least-one-memory-leaks-in-Mapguide-API-tp3212879p3224321.html
Sent from the MapGuide Internals mailing list archive at Nabble.com.
More information about the mapguide-internals
mailing list