How Garbage Collector works?

Rory Mcguire rjmcguire at gm_no_ail.com
Thu Aug 12 11:46:22 PDT 2010


Borneq wrote:

> Użytkownik "Lars T. Kyllingstad" <public at kyllingen.NOSPAMnet> napisał w
> wiadomości news:i40dhi$55q$1 at digitalmars.com...
>> Since the GC keeps track of the length of the memory block, it can also
>> tell whether the pointer is inside the memory block.
>>  if (pointer >= startOfBlock && pointer < startOfBlock + blockLength)
>>      doNotCollect();
> 
> How compute startOfBlock ? GC keep startOfBlock for each pointer (pointer
> consits of actual pointer and pointer to startOfBlock)?
> or search for pointer such Block that pointer betwen
> startOfBlock..startOfBlock + blockLength ?

GC doesn't keep track of pointer, it only keeps track of the start of 
allocated memory and the length of that allocated block.

it then has to scan to see if there are any pointers into that allocated 
block. This is why if you slice a subsection of an array the memory doesn't 
just get freed.

-Rory


More information about the Digitalmars-d mailing list