Thought on limiting scope of GC
Jerry
jlquinn at optonline.net
Fri Feb 14 08:24:08 PST 2014
"thedeemon" <dlang at thedeemon.com> writes:
> On Friday, 14 February 2014 at 04:41:43 UTC, Jerry wrote:
>> My thought is to have something like the following:
>>
>> GC.track();
>> auto obj = allocateStuff();
>> GC.cleanup(obj);
>>
>> The idea here is that track() tells GC to explicitly track all objects
>> created from that point until the cleanup call. The cleanup() call
>> tells gc to limit its collection to those objects allocated since the
>> track() call. The obj parameter tells gc to consider obj live.
>
> What if allocateStuff() writes address of some newly allocated object to a
> field of some old object existing before GC.track()? You can't just scan only
> objects created after GC.track(), this might create dangling references in the
> "old generation".
This is a concern. Rather than passing a single object into the
cleanup, a list of objects to consider live can be passed in. That
would cover at least some of these situations, but not all.
Would it still be useful given this limitation? Would it give someone
looking for tighter control over GC the tools they need?
More information about the Digitalmars-d
mailing list