Listing 5: Class template Boehmable
// $Id$ #include <gc_cpp.h> #include <list> #include <iostream> #include <string> using std::cout; using std::endl; using std::list; using std::string; long constructors = 0; long destructors = 0; template<class Super> class Boehmable : public Super, public virtual gc_cleanup { public: // Don't need any member functions. We inherit the // interfaces from Super and gc_cleanup. Boehmable () : Super (), gc_cleanup () { ++constructors; } virtual ~Boehmable () { ++destructors; } }; int main () { for (long i = 0; i < 10000; ++i) { list<int> *lst = new Boehmable< list<int> >; for (int j = 0; j < 1000; ++j) { lst->push_front (j); } list<string *> *strlst = new Boehmable< list<string *> >; for (int k = 0; k < 1000; ++k) { strlst->push_front (new Boehmable<string>); } } cout << "constructors " << constructors << ", destructors " << destructors << endl; return 0; }