]>
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 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/datetime.h"
25 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
26 #include "mondrian.xpm"
30 #error This program must be compiled in debug mode.
33 // Normally, new is automatically defined to be the
34 // debugging version. If not, this does it.
35 #if !defined(new) && defined(WXDEBUG_NEW) && wxUSE_MEMORY_TRACING && wxUSE_GLOBAL_MEMORY_OPERATORS
36 #define new WXDEBUG_NEW
39 // Define a new application type
40 class MyApp
: public wxApp
45 // Define a new frame type
46 class MyFrame
: public wxFrame
48 MyFrame(wxFrame
*parent
);
49 void OnQuit(wxCommandEvent
& event
);
56 // `Main program' equivalent, creating windows and returning main app frame
57 bool MyApp::OnInit(void)
59 // Create the main frame window
60 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
);
63 frame
->SetIcon(wxICON(mondrian
));
66 wxMenu
*file_menu
= new wxMenu
;
68 file_menu
->Append(wxID_EXIT
, _T("E&xit"));
69 wxMenuBar
*menu_bar
= new wxMenuBar
;
70 menu_bar
->Append(file_menu
, _T("File"));
71 frame
->SetMenuBar(menu_bar
);
73 // Make a panel with a message
74 wxPanel
*panel
= new wxPanel(frame
);
76 (void)new wxStaticText(panel
, wxID_ANY
, _T("Hello, this is a minimal debugging wxWidgets program!"), wxPoint(10, 10));
81 #if wxUSE_MEMORY_TRACING
82 wxDebugContext::SetCheckpoint();
86 wxBrush
* brush
= new wxBrush(*wxRED
);
87 wxBitmap
* bitmap
= new wxBitmap(100, 100);
89 // non-object allocation
90 char *ordinaryNonObject
= new char[1000];
92 wxString
*thing
= new wxString
;
95 wxDateTime
* date
= new wxDateTime
;
96 #endif // wxUSE_DATETIME
98 const char *data
= (const char*) thing
;
100 #if wxUSE_MEMORY_TRACING
101 // On MSW, Dump() crashes if using wxLogGui,
102 // so use wxLogStderr instead.
103 wxLog
* oldLog
= wxLog::SetActiveTarget(new wxLogStderr
);
105 wxDebugContext::PrintClasses();
106 wxDebugContext::Dump();
107 wxDebugContext::PrintStatistics();
109 // Set back to wxLogGui
110 delete wxLog::SetActiveTarget(oldLog
);
113 // Don't delete these objects, to force wxApp to flag a memory leak.
116 // delete[] ordinaryNonObject;
121 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
122 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
125 // My frame constructor
126 MyFrame::MyFrame(wxFrame
*parent
):
127 wxFrame(parent
, wxID_ANY
, _T("MemCheck wxWidgets Sample"), wxDefaultPosition
, wxSize(400, 200))
130 // Intercept menu commands
131 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))