William Soukoreff writes:
I'm new to Scheme, and new to Gambit, so I apologize if my question is silly.
You'll find that GC and wills work fine when you correct something whose effect is not specified by the definition of the language:
...
(define (circ-obj name) (let* ((data '(a . b) ) (func (lambda () (println "executing func for object "" name "" proc: " data)))) (set-car! data func) ; (set-cdr! data fund) ; (set! data func) func))
It is an error to set-car! a quoted pair (or any quoted datum). Scheme is not required to detect such errors, but the effect may not be what you expect. For example, Gambit could allocate just one pair, not a fresh pair every time.
Change '(a . b) to (cons 'a 'b) to create a mutable pair.
...
Notice that the will for object "three" never gets called, which I think means that the object hasn't been recollected by the garbage collector.
Anyway, all I'm really hoping for is an indication as to whether such circularly referenced objects should or should not be garbage collected.
Yes, such objects should get collected. The collector can and should remove objects that are no longer live in the sense of being accessible though a traversal that starts from root objects like global variables and code that is currently being executed.
This, too, is technically not specified by the language definition. Officially all objects live forever, but in practice unreachable memory can be recycled.