Boost logo

Boost :

Subject: Re: [boost] request for interest in a garbage collection library
From: Jonas Persson (l.j.persson_at_[hidden])
Date: 2009-04-17 10:49:14


Achilleas Margaritis skrev:
> Can you please elaborate on the problem of destructors? I have read some
> papers that say that gc and destructors don't play well together, but I
> did not really agree with that. An example would be appreciated.

One example is that, by default, your gc do not handle cyclic
dependencies correct because destructors are run when collected.

The following example gives an access violation on windows:

----------------------------------------------
   class Foo : public gc_object<Foo> {
   public:
     gc_ptr<Foo> m_next;
     std::string m_name;

     Foo(std::string name) : m_name(name) {}

     ~Foo() {
       m_next->lastGoodbye();
     }

     void lastGoodbye() { std::cout << "Bye " << m_name; }
   };
   void test_cycle() {
     gc_ptr<Foo> foo1 = new Foo("foo 1");
     foo1->m_next = new Foo("foo 2");
     foo1->m_next->m_next = foo1;

     foo1 = 0;
     gc::collect();
   }
----------------------------------------------

   / Jonas


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk