]>
git.saurik.com Git - wxWidgets.git/blob - samples/memcheck/memcheck.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Memory-checking sample
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
22 #include "wx/datetime.h"
24 #ifndef wxHAS_IMAGES_IN_RESOURCES
25 #include "../sample.xpm"
29 #error This program must be compiled in debug mode.
32 // Normally, new is automatically defined to be the
33 // debugging version. If not, this does it.
34 #if !defined(new) && defined(WXDEBUG_NEW) && wxUSE_MEMORY_TRACING && wxUSE_GLOBAL_MEMORY_OPERATORS
35 #define new WXDEBUG_NEW
38 // Define a new application type
39 class MyApp
: public wxApp
44 // Define a new frame type
45 class MyFrame
: public wxFrame
47 MyFrame(wxFrame
*parent
);
48 void OnQuit(wxCommandEvent
& event
);
55 // `Main program' equivalent, creating windows and returning main app frame
56 bool MyApp::OnInit(void)
58 if ( !wxApp::OnInit() )
61 // Create the main frame window
62 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
);
65 frame
->SetIcon(wxICON(sample
));
68 wxMenu
*file_menu
= new wxMenu
;
70 file_menu
->Append(wxID_EXIT
, wxT("E&xit"));
71 wxMenuBar
*menu_bar
= new wxMenuBar
;
72 menu_bar
->Append(file_menu
, wxT("File"));
73 frame
->SetMenuBar(menu_bar
);
75 // Make a panel with a message
76 wxPanel
*panel
= new wxPanel(frame
);
78 (void)new wxStaticText(panel
, wxID_ANY
, wxT("Hello, this is a minimal debugging wxWidgets program!"), wxPoint(10, 10));
83 #if wxUSE_MEMORY_TRACING
84 wxDebugContext::SetCheckpoint();
88 wxBrush
* brush
= new wxBrush(*wxRED_BRUSH
);
89 wxBitmap
* bitmap
= new wxBitmap(100, 100);
91 // non-object allocation
92 char *ordinaryNonObject
= new char[1000];
94 wxString
*thing
= new wxString
;
97 wxDateTime
* date
= new wxDateTime
;
98 #endif // wxUSE_DATETIME
100 const char *data
= (const char*) thing
;
102 #if wxUSE_MEMORY_TRACING
103 // On MSW, Dump() crashes if using wxLogGui,
104 // so use wxLogStderr instead.
105 wxLog
* oldLog
= wxLog::SetActiveTarget(new wxLogStderr
);
107 wxDebugContext::PrintClasses();
108 wxDebugContext::Dump();
109 wxDebugContext::PrintStatistics();
111 // Set back to wxLogGui
112 delete wxLog::SetActiveTarget(oldLog
);
115 // Don't delete these objects, to force wxApp to flag a memory leak.
118 // delete[] ordinaryNonObject;
123 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
124 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
127 // My frame constructor
128 MyFrame::MyFrame(wxFrame
*parent
):
129 wxFrame(parent
, wxID_ANY
, wxT("MemCheck wxWidgets Sample"), wxDefaultPosition
, wxSize(400, 200))
132 // Intercept menu commands
133 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))