[Gc] Error in simple GC test

Christophe Meessen meessen at cppm.in2p3.fr
Sun Apr 22 06:28:12 PDT 2007


Hello,

I did run with success the test program provided with gc. But when I try
my own program it fails.
I'm using VC++ 2003 and libgc6.8. I'am compiling for multithreaded debug
and the GC_malloc call fails.
Beside disabling the use managed code option in the project property,
the options are standard.
I use the library compiled for windows static threads and debug support.
Same problem when using the none debug library version.
The problem occurs when calling FASTLOCK() in GC_malloc.

I also tried with adding #define GC_THREADS before including gc_cpp.h.
In this case the GC_malloc call succeeds but no destructor gets ever
called. The GC_gcollect(); does nothing and even adding a Sleep of 10
seconds after it doesn't help. How can I be sure, in this case, that
libgc works and my objects are properly collected ?

Here is the source code I tried.

#include <iostream>
#include <gc_cpp.h>

class Test : public gc_cleanup
{
public:
    Test( int i ) : m_n(i) {}
    ~Test() { std::cout << "~Test: " << m_n << std::endl; }
    int m_n;
};
class Derived: public Test
{
public:
    Derived( int i) : Test(i) {}
    ~Derived() { std::cout << "~Derived: " << m_n << std::endl; }
};

int main( int argc, char* argv[] )
{
  GC_INIT();
    {
       std::cout << "Start" << std::endl;
       Test* t1 = new Test(1);
    }

    std::cout << "Collect" << std::endl;
    GC_gcollect();

    std::cout << "Done" << std::endl;
    return 0;
}




More information about the Gc mailing list