]>
git.saurik.com Git - wxWidgets.git/blob - samples/memcheck/memcheck.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Memory-checking sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/datetime.h"
30 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
31 #include "mondrian.xpm"
35 #error This program must be compiled in debug mode.
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
44 // Define a new application type
45 class MyApp
: public wxApp
50 // Define a new frame type
51 class MyFrame
: public wxFrame
53 MyFrame(wxFrame
*parent
);
54 void OnQuit(wxCommandEvent
& event
);
61 // `Main program' equivalent, creating windows and returning main app frame
62 bool MyApp::OnInit(void)
64 // Create the main frame window
65 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
);
68 frame
->SetIcon(wxICON(mondrian
));
71 wxMenu
*file_menu
= new wxMenu
;
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
);
78 // Make a panel with a message
79 wxPanel
*panel
= new wxPanel(frame
);
81 (void)new wxStaticText(panel
, -1, "Hello, this is a minimal debugging wxWidgets program!", wxPoint(10, 10));
86 wxDebugContext::SetCheckpoint();
88 wxString
*thing
= new wxString
;
91 wxDateTime
* date
= new wxDateTime
;
92 #endif // wxUSE_DATETIME
94 // non-object allocation
95 char *ordinaryNonObject
= new char[1000];
97 const char *data
= (const char*) thing
;
99 // On MSW, Dump() crashes if using wxLogGui,
100 // so use wxLogStderr instead.
101 wxLog
* oldLog
= wxLog::SetActiveTarget(new wxLogStderr
);
103 wxDebugContext::PrintClasses();
104 wxDebugContext::Dump();
105 wxDebugContext::PrintStatistics();
107 // Set back to wxLogGui
108 delete wxLog::SetActiveTarget(oldLog
);
110 // Don't delete these objects, to force wxApp to flag a memory leak.
113 // delete[] ordinaryNonObject;
118 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
119 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
122 // My frame constructor
123 MyFrame::MyFrame(wxFrame
*parent
):
124 wxFrame(parent
, -1, "MemCheck wxWidgets Sample", wxPoint(-1, -1), wxSize(400, 200))
127 // Intercept menu commands
128 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))