After creating a sizer, allocating it and not deleting it,
memory leaks remain in VisualStudio 2008.
Trying to delete them fails to close the window in which they were created.
Any ideas how to release otherwise the memory ??
wxSizers pointers create memory leaks in VS2008
-
- Earned a small fee
- Posts: 14
- Joined: Thu Dec 11, 2008 3:01 pm
-
- Super wx Problem Solver
- Posts: 264
- Joined: Mon Aug 07, 2006 3:25 pm
- Location: Baia Mare, Romania
- Contact:
Hi.
How does your code look?
If you create a sizer on the (unsing new), it's a good idea to assign that sizer to a control/window (something that inherits wxWindow) using the SetSizer() method
http://docs.wxwidgets.org/stable/wx_wxw ... owsetsizer
This way the sizer will be deleted automatically when the control/window is destroy.
If you create more sizers, you can add them as child to the main sizer of a control/window.
Make sure you add a sizer as a child only once to another sizer.
If you follow these guidlines, your sizers will always be freed.
Don't leave anything "hanging in the air". Just because you create a sizer inside a control/class will not assign that sizer to that control. If you do need such sizers for whatever reasons, make sure you save the pointer to it and delete it when you no longer need it.
Hope this helps.
Regards
How does your code look?
If you create a sizer on the (unsing new), it's a good idea to assign that sizer to a control/window (something that inherits wxWindow) using the SetSizer() method
http://docs.wxwidgets.org/stable/wx_wxw ... owsetsizer
This way the sizer will be deleted automatically when the control/window is destroy.
If you create more sizers, you can add them as child to the main sizer of a control/window.
Make sure you add a sizer as a child only once to another sizer.
If you follow these guidlines, your sizers will always be freed.
Don't leave anything "hanging in the air". Just because you create a sizer inside a control/class will not assign that sizer to that control. If you do need such sizers for whatever reasons, make sure you save the pointer to it and delete it when you no longer need it.
Hope this helps.
Regards
Last edited by framepointer on Thu Jan 15, 2009 8:33 pm, edited 1 time in total.
Software is like sex,
It's better when it's free.
~Linus Torvalds
It's better when it's free.
~Linus Torvalds
-
- Experienced Solver
- Posts: 70
- Joined: Fri Nov 07, 2008 4:25 pm
- Location: Saint-Petersburg, Russia
-
- Earned a small fee
- Posts: 14
- Joined: Thu Dec 11, 2008 3:01 pm
I use wxFormBuilder to create the dialog:
xx.h
wxBoxSizer* m_pWholeSizer;
xx.cpp
Create()
{
m_pWholeSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(m_pWholeSizer);
}
Delete()
{
if(m_pWholeSizer)
{
delete m_pWholeSizer;
m_pWholeSizer = NULL;
}
}
and that delete is called in destructor, if i do not perform
the pointer deletion everything closes corectly but then i VS2008 shows memory leak.
If i delete it it hangs on delete itself now the dialog has not been destroyed yet but its internal controls have already deleted by myself and now on delete sier attempt
it fails inside wxSizer Destructor.
xx.h
wxBoxSizer* m_pWholeSizer;
xx.cpp
Create()
{
m_pWholeSizer = new wxBoxSizer(wxVERTICAL);
SetSizer(m_pWholeSizer);
}
Delete()
{
if(m_pWholeSizer)
{
delete m_pWholeSizer;
m_pWholeSizer = NULL;
}
}
and that delete is called in destructor, if i do not perform
the pointer deletion everything closes corectly but then i VS2008 shows memory leak.
If i delete it it hangs on delete itself now the dialog has not been destroyed yet but its internal controls have already deleted by myself and now on delete sier attempt
it fails inside wxSizer Destructor.
Is the dialog created on the stack of the heap?
If you are creating it on the heap with new, you shouldn't delete it. But call wxDialog::Destroy() instead, as it will take care of deleting all of its children.
Also as has already been asked but not to clearly answered. How exactly are you determining that there is a leak?
-Max
If you are creating it on the heap with new, you shouldn't delete it. But call wxDialog::Destroy() instead, as it will take care of deleting all of its children.
Also as has already been asked but not to clearly answered. How exactly are you determining that there is a leak?
-Max