When to use delete Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

When to use delete

Post by sethjackson » Mon Oct 10, 2005 9:45 pm

I want to know if it is ok to use delete on a wxGLCanvas object.
In my MainFrame destructor I have this.

Code: Select all

MainFrame::~MainFrame()
{
    delete g_pGLCanvas;
}
wher g_pGlCanvas is a pointer to a wxGLCanvas object.

Is this OK to do?

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Tue Oct 11, 2005 1:37 am

You should use Destroy() (g_pGLCanvas->Destroy()) for objects derived from wxEvtHandler (it prevents lingering events from being processed using a non-existent event handler). Also, since your wxGLCanvas is most certainly a child of another wxWindow or wxWindow derived class you can safely not do anything. wxWidgets will automatically delete it as it deletes the parent window.

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Tue Oct 11, 2005 5:59 am

ya, but don't forgot to pass (this) parent handle to the child controls and you can safely forgot them or call Destroy on child controls derived from wxEvtHandler. For classes that don't take the parent handle, you have to call delete for objects created with new.

sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson » Tue Oct 11, 2005 3:01 pm

So I don't have to do anything at all. :) Thanks much.

Post Reply