]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/memcheck/memcheck.cpp
Moved the cleanup code to an EVT_WINDOW_DESTROY handler.
[wxWidgets.git] / samples / memcheck / memcheck.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: memcheck.cpp
3// Purpose: Memory-checking sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#pragma interface
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
28#include "wx/datetime.h"
29
30#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
31#include "mondrian.xpm"
32#endif
33
34#ifndef __WXDEBUG__
35#error This program must be compiled in debug mode.
36#endif
37
38// Normally, new is automatically defined to be the
39// debugging version. If not, this does it.
40#if !defined(new) && defined(WXDEBUG_NEW)
41#define new WXDEBUG_NEW
42#endif
43
44// Define a new application type
45class MyApp: public wxApp
46{ public:
47 bool OnInit(void);
48};
49
50// Define a new frame type
51class MyFrame: public wxFrame
52{ public:
53 MyFrame(wxFrame *parent);
54 void OnQuit(wxCommandEvent& event);
55
56DECLARE_EVENT_TABLE()
57};
58
59IMPLEMENT_APP(MyApp)
60
61// `Main program' equivalent, creating windows and returning main app frame
62bool MyApp::OnInit(void)
63{
64 // Create the main frame window
65 MyFrame *frame = new MyFrame((wxFrame *) NULL);
66
67 // Give it an icon
68 frame->SetIcon(wxICON(mondrian));
69
70 // Make a menubar
71 wxMenu *file_menu = new wxMenu;
72
73 file_menu->Append(wxID_EXIT, "E&xit");
74 wxMenuBar *menu_bar = new wxMenuBar;
75 menu_bar->Append(file_menu, "File");
76 frame->SetMenuBar(menu_bar);
77
78 // Make a panel with a message
79 wxPanel *panel = new wxPanel(frame);
80
81 (void)new wxStaticText(panel, -1, "Hello, this is a minimal debugging wxWindows program!", wxPoint(10, 10));
82
83 // Show the frame
84 frame->Show(TRUE);
85
86 wxDebugContext::SetCheckpoint();
87
88 wxString *thing = new wxString;
89
90#if wxUSE_DATETIME
91 wxDateTime* date = new wxDateTime;
92#endif // wxUSE_DATETIME
93
94 // non-object allocation
95 char *ordinaryNonObject = new char[1000];
96
97 const char *data = (const char*) thing ;
98
99 // On MSW, Dump() crashes if using wxLogGui,
100 // so use wxLogStderr instead.
101 wxLog* oldLog = wxLog::SetActiveTarget(new wxLogStderr);
102
103 wxDebugContext::PrintClasses();
104 wxDebugContext::Dump();
105 wxDebugContext::PrintStatistics();
106
107 // Set back to wxLogGui
108 delete wxLog::SetActiveTarget(oldLog);
109
110 // Don't delete these objects, to force wxApp to flag a memory leak.
111// delete thing;
112// delete date;
113// delete[] ordinaryNonObject;
114
115 return TRUE;
116}
117
118BEGIN_EVENT_TABLE(MyFrame, wxFrame)
119 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
120END_EVENT_TABLE()
121
122// My frame constructor
123MyFrame::MyFrame(wxFrame *parent):
124 wxFrame(parent, -1, "MemCheck wxWindows Sample", wxPoint(-1, -1), wxSize(400, 200))
125{}
126
127// Intercept menu commands
128void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
129{
130 Close(TRUE);
131}
132