[Gc] Re: GC needs to be invoked manually

Larry Evans cppljevans at cox-internet.com
Sat Aug 13 15:02:48 PDT 2005

On 08/11/2005 03:48 PM, Martin Wartens wrote:
> I was able to narrow down the problem to the code given below. Running it gives
> struct Element;
> //row of sparse matrix, pointers to elements keyed by unsigned
> typedef std::map<unsigned, Element*, std::less<unsigned>, 
> traceable_allocator<  std::pair<const unsigned, Element*>  > > Row_T;
> //sparse matrix, pointers to rows keyed by unsigned
> typedef std::map<unsigned, Row_T, std::less<unsigned>, 
> traceable_allocator<  std::pair<const unsigned, Row_T>  > > Matrix_T;
> //each element holds a sparse matrix of elements,
> //this is a tree-like data structure 
> struct Element: public gc_cleanup{
>         Matrix_T mat;
> };
> void testgc(){
>         Element* someElement = new Element();
>         for (unsigned i=0; i<10000; i++)
>         {
>                 Element *n1 = new Element();
>                 Element *n2 = new Element();
>                 n2->mat[1][1] = n1;
>                 n2->mat[2][2] = n1;
>                 n2->mat[3][3] = someElement;
>                 n2->mat[4][4] = someElement;
Don't the above 2 assignments make the data structure a graph instead of
a tree?
>         }
I vaguely recall something about the collector not being able to
collect cycles in nodes with finalizers because it cannot know
in which order to call the finalizers.  I can't even remember
whether finalizer is the correct term either.  Anyway, by finalizer,
I mean something that cleans up the node, somewhat like a c++ DTOR.


More information about the Gc mailing list