class BaseBitmap {
BaseBitmap() {
}
~BaseBitmap() {
}
public:
static int allocs;
static int deallocs;
static BaseBitmap* Alloc() {
allocs++;
return new BaseBitmap;
}
static void Free(BaseBitmap*& ptr) {
if (ptr) {
deallocs++;
delete ptr;
ptr = NULL;
}
}
};
int BaseBitmap::allocs = 0;
int BaseBitmap::deallocs = 0;
class MyDialog {
std::vector<BaseBitmap*> bmps;
public:
~MyDialog() {
std::vector<BaseBitmap*>::iterator it = bmps.begin();
for (; it != bmps.end(); it++) {
BaseBitmap::Free(*it);
}
bmps.clear();
}
int Message(void* node, int msgType, void* pData) {
if (msgType == 100) {
BaseBitmap* bmp = BaseBitmap::Alloc();
if (bmp) {
std::cout << "Adding bitmap..\n";
bmps.push_back(bmp);
}
}
return 1;
}
};
int main() {
/* scope */ {
MyDialog dlg;
dlg.Message(NULL, 20, NULL);
dlg.Message(NULL, 100, NULL);
dlg.Message(NULL, 100, NULL);
}
std::cout << "BaseBitmap Allocs: " << BaseBitmap::allocs << "\n";
std::cout << "BaseBitmap Deallocs: " << BaseBitmap::deallocs << "\n";
}