template struct life_time_controller { typedef life_time_controller me; life_time_controller() : id(new_id()) { collection().insert(this); } life_time_controller(const me&) : id(new_id()) { collection().insert(this); } ~life_time_controller() { collection().erase (this); } const int id; private: static int new_id() { static int ret=0; ++ret; return ret; // set conditional break point there } struct collection_type { boost::unordered_set living_objects; ~collection_type() { if(!living_objects.empty()) { std::cerr << "type: " << typeid(T).name() << " living_objects: " << living_objects.size() << " ids: "; BOOST_FOREACH(void*ptr, living_objects) std::cerr << static_cast*>(ptr)->id << " "; std::cerr << std::endl; } } }; static boost::unordered_set& collection() { static collection_type ret; return ret.living_objects; } }; template struct unit : life_time_controller //, ... { // ... }; struct A : unit {}; struct B : unit {}; struct C : unit {}; int main(int argc, char *argv[]) { new A(); new B[3](); return 0; }