wxWindows 2 FAQ: Questions common to all platforms

See also top-level FAQ page.

### List of questions in this category

- Who deletes all the windows I create?
- How to create and use custom events?
- How can I set the TAB order of the controls?

### Who deletes all the windows I create?

All windows and controls in wxWindows programs are created using `new` but you shouldn't use `delete` to free them. This doesn't result in memory leaks because wxWindows takes care of this: all objects derived from wxWindow will be deleted automatically by the library when the corresponding real, on screen, window is destroyed. Thus, the top level window objects are deleted when you call `Close()` or `Destroy()` and all the child windows are deleted just before the parent window is. More details about the top level windows can be found in the ``Window deletion overview'' in the manual.

wxWindows also automatically deletes some other kind of the objects, notably the sizer or constraint associated with the window -- this happens just before the window itself is deleted. The sizers, in turn, delete their child sizers automatically as well so in a typical situation you don't have to worry about freeing the sizers you create. Note, however, that if you `Remove()` a sizer from the window, it isn't automatically deleted any more and you are responsable for doing this.

### How to create and use custom events?

Please look at the `event` wxWindows sample source code, it shows how to do this among other things. Note that the way custom events are defined has changed in wxWindows 2.3.1 as compared to the previous releases.

### How can I set the TAB order of the controls?

Unfortunately in the current wxWindows version (2.4.0 as of this writing) this is not possible: the TAB order of the control (that is, the order in which the controls gain focus when the user repeatedly presses the `<TAB>` key) is fixed and is the same as the order of the controls creation.

Changing this should become possible in future versions of wxWindows as soon as we come up with a nice API for this feature.