Thread overview
How does GC.addRange work?
Sep 20, 2014
Gary Willoughby
Sep 20, 2014
ketmar
Sep 20, 2014
Gary Willoughby
Sep 20, 2014
ketmar
Sep 21, 2014
Gary Willoughby
September 20, 2014
How does GC.addRange work? i.e. what is it doing? I'm assuming reading the docs that it adds a range for the GC to scan but what actually happens? Does the GC look into this range and check for the existence of pointers it's currently managing?

For example, if i nulled a pointer in the range i added would that trigger the GC to collect that resource on the next sweep? (assuming it was the last reference.)
September 20, 2014
On Sat, 20 Sep 2014 20:14:35 +0000
Gary Willoughby via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:

> How does GC.addRange work? i.e. what is it doing? I'm assuming reading the docs that it adds a range for the GC to scan but what actually happens? Does the GC look into this range and check for the existence of pointers it's currently managing?
yes. this adds GC "root". but normal GC root is just a single pointer, and "range root" as a memory region that will be scanned for pointers (i.e. something like "array of pointers").

note that scan is conservative, so if you happen to have some integer value that can be interpreted as pointer to GC-managed memory, it will be considered as pointer.


September 20, 2014
On Saturday, 20 September 2014 at 20:44:18 UTC, ketmar via Digitalmars-d-learn wrote:
> note that scan is conservative, so if you happen to have some integer
> value that can be interpreted as pointer to GC-managed memory, it will
> be considered as pointer.

So zeroing values will inform the GC the reference has gone?
September 20, 2014
On Sat, 20 Sep 2014 22:21:13 +0000
Gary Willoughby via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:

> So zeroing values will inform the GC the reference has gone?
yes.


September 21, 2014
On Saturday, 20 September 2014 at 23:08:08 UTC, ketmar via Digitalmars-d-learn wrote:
> On Sat, 20 Sep 2014 22:21:13 +0000
> Gary Willoughby via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>
>> So zeroing values will inform the GC the reference has gone?
> yes.

Thanks, i just wanted to make it clear in my mind.
September 22, 2014
On 9/21/14 3:00 PM, Gary Willoughby wrote:
> On Saturday, 20 September 2014 at 23:08:08 UTC, ketmar via
> Digitalmars-d-learn wrote:
>> On Sat, 20 Sep 2014 22:21:13 +0000
>> Gary Willoughby via Digitalmars-d-learn
>> <digitalmars-d-learn@puremagic.com> wrote:
>>
>>> So zeroing values will inform the GC the reference has gone?
>> yes.
>
> Thanks, i just wanted to make it clear in my mind.

Just to be crystal clear, zeroing values in that range will make the GC able to collect the memory that those values previously pointed at. However, you have to remove the range in order for the GC to ignore that data. In other words, if you zero that memory, the GC will continue to scan those zeros until you GC.removeRange it.

-Steve