[Gc] Re: GC needs to be invoked manually

Larry Evans cppljevans at cox-internet.com
Mon Aug 15 10:39:50 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
> Elements created: 20001
> Elements destroyed: 0
[snip]
> void testgc(){
>         Element* someElement = new Element();
>         for (unsigned i=0; i<10000; i++)
[snip]
>         cout << "Elements created: " << Element::created << endl;
>         cout << "Elements destroyed: " << Element::destroyed << endl;
Nothing's destroyed yet because there's still a root pointer,
someElement, on the stack at this point.
> }
> 
> int main()
> {
>         testgc();
Try adding an explicit call to the collector here, then move the 2 cout
calls in testgc to after the collector call.
> }

HTH.



More information about the Gc mailing list