<div dir="ltr">William,<div><br></div><div>Circular GC refs are GC:ed also yes.<div><br></div><div>The weird behavior you see about "three" not gc:ing appears because an error in your code - it is an error with Gambit, to mutate the content of a list constant - as you see if you compile your code you get a runtime error on the set-car! '(..  , so you need to replace the '( with (cons .</div>

<div><br></div><div>With this correction, you get the proper behavior in both execution modes.</div><div><br></div><div>While most things in G. are obvious, this particular requirement that you shouldn't mutate list constant contents was one was not too much and I hope this helps :))</div>

<div><br></div><div>Mikael</div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-02-18 9:29 GMT+01:00 William Soukoreff <span dir="ltr"><<a href="mailto:william@soukoreff.com" target="_blank">william@soukoreff.com</a>></span>:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
I'm new to Scheme, and new to Gambit, so I apologize if my question<br>
is silly.<br>
<br>
I think that the concept of wrapping a (let …) around a (lambda …) is<br>
really neat, which got me wondering about what happens if you create<br>
a circular reference to a lambda from the scope of the let that surrounds<br>
it…  in particular, should such a circular reference get garbage collected?<br>
(And if so, WOW, that's a pretty clever garbage collector!)<br>
<br>
In the following program I create 3 objects ("one", "two", and "three"), and<br>
create wills for them.  Then I destroy my references to all three objects<br>
and call the garbage collector.  The result is that 2 of the 3 objects gets<br>
garbage collected.<br>
<br>
My question is, is this the expected behaviour, or have I stumbled across<br>
something more sinister?<br>
<br>
Here's the code:<br>
<br>
<br>
- - - CODE STARTS HERE - - -<br>
<br>
<br>
(define (circ-obj name)<br>
   (let* ((data '(a . b) )<br>
          (func (lambda () (println "executing func for object \"" name<br>
"\" proc: " data))))<br>
      (set-car! data func)<br>
;      (set-cdr! data fund)<br>
;      (set! data func)<br>
      func))<br>
<br>
<br>
<br>
(define one (circ-obj 'one))<br>
(println "CREATING ONE")<br>
(pp one)<br>
(one)<br>
<br>
(println)<br>
<br>
(define two (circ-obj 'two))<br>
(println "CREATING TWO")<br>
(pp two)<br>
(two)<br>
<br>
(println)<br>
<br>
(define three (circ-obj 'three))<br>
(println "CREATING THREE")<br>
(pp three)<br>
(three)<br>
<br>
(println)<br>
<br>
<br>
(println "CREATING WILLS")<br>
(define wone   (make-will one   (lambda (obj) (println "killing one "<br>
obj))))<br>
(define wtwo   (make-will two   (lambda (obj) (println "killing two "<br>
obj))))<br>
(define wthree (make-will three (lambda (obj) (println "killing three "<br>
obj))))<br>
<br>
(println)<br>
<br>
(println "DESTROYING ONE")<br>
(set! one #f)<br>
(##gc)<br>
<br>
(println)<br>
<br>
(println "DESTROYING TWO")<br>
(set! two #f)<br>
(##gc)<br>
<br>
(println)<br>
<br>
(println "DESTROYING THREE")<br>
(set! three #f)<br>
(##gc)<br>
<br>
(println)<br>
<br>
(println "Done!")<br>
<br>
<br>
- - - CODE ENDS HERE - - -<br>
<br>
<br>
When I run this I get the following result:<br>
<br>
<br>
- - - SAMPLE RUN STARTS HERE - - -<br>
<br>
CREATING ONE<br>
(lambda () (println "executing func for object \"" name "\" proc: " data))<br>
executing func for object "one" proc: #<procedure #2 one>b<br>
<br>
CREATING TWO<br>
(lambda () (println "executing func for object \"" name "\" proc: " data))<br>
executing func for object "two" proc: #<procedure #3 two>b<br>
<br>
CREATING THREE<br>
(lambda () (println "executing func for object \"" name "\" proc: " data))<br>
executing func for object "three" proc: #<procedure #4 three>b<br>
<br>
CREATING WILLS<br>
<br>
DESTROYING ONE<br>
killing one #<procedure #2><br>
<br>
DESTROYING TWO<br>
killing two #<procedure #3><br>
<br>
DESTROYING THREE<br>
<br>
Done!<br>
<br>
- - - SAMPLE RUN ENDS HERE - - -<br>
<br>
<br>
Notice that the will for object "three" never gets called, which I think<br>
means that the object hasn't been recollected by the garbage collector.<br>
<br>
Anyway, all I'm really hoping for is an indication as to whether such<br>
circularly referenced objects should or should not be garbage collected.<br>
<br>
Thanks!<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</blockquote></div><br></div>