Re: Boehm GC problem
Ivan Maidanski <ivmai-JGs/[email protected]>
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <[email protected]> |
Hi Vadim, It is better to send questions to the ML ([email protected]). Probably someone on the list knows the answer. I have tried your sample but it worked for me (on cygwin), the output: 1000 1 1001 1 Just for reference, I used the recent BDWGC snapshot and following commands to build the sample: gcc -I include -c extra/gc.c g++ -I include test_app.cpp gc.o [Translated] Fri, 27 Dec 2013, 16:51 +04:00 from Vadim <[email protected]>: >Hi. >I have an issue with Boehm GC, probably you could help me. >I found the solution http://www.drdobbs.com/the-boehm-collector-for-c-and-c/184401632?pgno=6 how to use the collector for the std types but it does not work for me. > >The code: > >#include "app.h" I replaced it to: #include <iostream> #include <stdlib.h> #include "gc_cpp.h" > >using namespace std; > >long allocated = 0; > >template<class Super> >class Boehmable : public Super, public virtual gc_cleanup >{ >public: >Boehmable() : Super(), gc_cleanup() { allocated++; } >virtual ~Boehmable() { allocated--; } >}; > >class MyClass >{ >public: >MyClass() {}; >~MyClass() {}; >}; > >int main(int argc, char **argv) >{ >for (int i = 0; i < 1000; i++) >{ >new Boehmable<MyClass>(); >} > >cout << allocated << endl; // 1000 >GC_gcollect(); >cout << allocated << endl << endl; // 1 - It works > >for (int i = 0; i < 1000; i++) >{ >new Boehmable<string>(); >} > >cout << allocated << endl; // 1001 >GC_gcollect(); >cout << allocated << endl << endl; // 1001 - Does not work! > >system("pause"); > >return 0; >} > >Does not work for list, vector, etc. types neither. Regards, Ivan _______________________________________________ Gc mailing list Gc-V9/[email protected] http://www.hpl.hp.com/hosted/linux/mail-archives/gc/