Array of class intances

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Wed Apr 9 17:00:12 PDT 2008


Jarrett Billingsley wrote:
> "YY" <yyudhistira at hotmail.com> wrote in message 
>> If I only do this :
>>
>> inst.length = 0;
>>
>> will all the instance items be automatically captured by garbage 
>> collector?
> 
> If there are no other references to them, they will. 

While the G would be well within its rights to collect them if no other 
references exist, I'm pretty sure the current one doesn't.
The problem is that setting the length to 0 will only modify the array 
reference, not the data that was in it. The memory block will still be 
referenced and the current GC doesn't know what parts of a memory block 
are actually in use.
The array contents cannot generally be cleared if the length of a 
reference is set to 0 either, since there may be other references. So as 
long as a pointer or array references that block of memory (and yes, a 
0-length array can still reference a block of memory, namely the one 
that will be used when '~=' is used on it) it won't be collected.


More information about the Digitalmars-d-learn mailing list