[Gc] Multiple inheritance issue

Boehm, Hans hans.boehm at hp.com
Fri Oct 13 13:46:02 PDT 2006


What's GC_all_interior_pointers?   It should be set for this to work,
which it should be for default builds.  Otherwise, you need to call
GC_register_displacement on the offset of IFoo within Foo.

Hans

> -----Original Message-----
> From: gc-bounces at napali.hpl.hp.com 
> [mailto:gc-bounces at napali.hpl.hp.com] On Behalf Of Christian Gudrian
> Sent: Friday, October 13, 2006 1:32 PM
> To: gc at napali.hpl.hp.com
> Subject: [Gc] Multiple inheritance issue
> 
> Hello!
> 
> I am currently having a problem where the garbage collector 
> prematurely reclaims an object which is an instance of a 
> class with two base classes:
> 
> // --------------------------------------------------
> #include "gc.h"
> #include "gc_cpp.h"
> 
> class IFoo
> {
> public:
>     virtual void foo() = 0;
> };
> 
> class Foo : public gc_cleanup, public IFoo {
> public:
>     ~Foo() {}
>     void foo() {}
> };
> 
> Foo * f = new Foo();
> IFoo * i = f;
> 
> int main()
> {
>     f = 0;
>     GC_gcollect();
>     i->foo();
>     return 0;
> }
> // --------------------------------------------------
> 
> The second call to GC_gcollect() destroys the Foo instance, 
> though i still holds a live pointer to it.  The foo() method 
> then acts upon an invalid instance.
> 
> At the beginning of main() both GC_base(f) and GC_base(i) 
> point to the same location in memory.  Furthermore 
> GC_is_static_root(&i) and
> GC_is_static_root(&f) both return 1.  What makes the garbage 
> collector ignore the reference to the instance in i?  And how 
> do I work around this behaviour?
> 
> Christian
> 
> P.S.: I'm using the garbage collector on Windows XP with Borland
> C++Builder 2006.
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list