allocating and deleting wxwidgets objects
in general, classes derived from wxwindow must dynamically allocated
with new and deleted with delete. if you delete a window,
all of its children and descendants will be automatically deleted,
so you don't need to delete these descendants explicitly.
when deleting a frame or dialog, use destroy rather than delete so
that the wxwidgets delayed deletion can take effect. this waits until idle time
(when all messages have been processed) to actually delete the window, to avoid
problems associated with the gui sending events to deleted windows.
don't create a window on the stack, because this will interfere
with delayed deletion.
if you decide to allocate a c++ array of objects (such as wxbitmap) that may
be cleaned up by wxwidgets, make sure you delete the array explicitly
before wxwidgets has a chance to do so on exit, since calling delete on
array members will cause memory problems.
wxcolour can be created statically: it is not automatically cleaned
up and is unlikely to be shared between other objects; it is lightweight
enough for copies to be made.
beware of deleting objects such as a wxpen or wxbitmap if they are still in use.
windows is particularly sensitive to this: so make sure you
make calls like wxdc::setpen(wxnullpen) or wxdc::selectobject(wxnullbitmap) before deleting
a drawing object that may be in use. code that doesn't do this will probably work
fine on some platforms, and then fail under windows.
|