I do not use winblows but some hints:
The OnClose() handler is connected to wxEVT_WINDOW_CLOSE by default. This event is triggered by Close() itself so that your code snippet might contain an infinite loop. wxWidgets states that it is protected from that loop but it also tells you that you should not rely too much on it
The normal processing of wxEVT_WINDOW_CLOSE is calling Destroy() instead of Close().
The example programs in wxWidgets use OnQuit() rather than OnClose(). Either use OnQuit() and call Close() from OnQuit() or Connect() to wxEVT_WINDOW_CLOSE and call Destroy() from the handler. The later method is necessary if your main window is a modeless dialog (closing a modeless dialog = hiding it by default, not quitting it).