GC does not delete subclass

guslay guslay at gmail.com
Wed Dec 19 08:35:42 PST 2007


Matthias Thurau Wrote:

> "The problem is this case is a register with the value, not
> a memory location"
> 
> I don t understand what a register is :( Could you give me an example? And maybe Your workaround for that?
> 
> greetings

A register is a small storage available to the cpu to make computation. http://en.wikipedia.org/wiki/Processor_register

However I doubt that Sean's assumption is valid in this case. I've modified the original testcase to call

{ MyClass A =    new MyClass(); }

up to a couple tens of THOUSAND times.

Whereas the scoped class is destroyed on scope exit, the destructor of the embedded object is only called at program termination (as described). Collect as
no effect on them, no matter how many instances are created.

That would be a lot of registers!

Some other things I have noticed:

* Without scope attribute, all instances of both classes are destroyed on collect. No problem.

* With the scope attribute, embedded instances are destroyed in reverse order of creation, by group of 256.

Sub_Destructor2 255
...
Sub_Destructor2 0
Sub_Destructor2 511
...
Sub_Destructor2 256
..

This GC behavior is stranger than usual...

(using Phobos.)




More information about the Digitalmars-d mailing list