www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How does GC.addRange work?

reply "Gary Willoughby" <dev nomad.so> writes:
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.)
Sep 20 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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=20
 reading the docs that it adds a range for the GC to scan but what=20
 actually happens? Does the GC look into this range and check for=20
 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.
Sep 20 2014
parent reply "Gary Willoughby" <dev nomad.so> writes:
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?
Sep 20 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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.
Sep 20 2014
parent reply "Gary Willoughby" <dev nomad.so> writes:
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.
Sep 21 2014
parent Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Sep 22 2014
prev sibling parent "kiran kumari" <kiranfabzen gmail.com> writes:
On Saturday, 20 September 2014 at 20:14:36 UTC, Gary Willoughby
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?

 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.)
see more example http://techgurulab.com/course/java-quiz-online/
Sep 24 2014