[gambit-list] gc problems with streams/recursions

Christian christian at pflanze.mine.nu
Sun Oct 30 22:41:00 EST 2005


At 22:49 Uhr +0100 30.10.2005, I wrote:
>While playing with streams, I think I've noticed that the stream
>"head" is not garbage collected while traversing the stream even if it
>is not referenced by user data structures anymore.

Sorry, please accept my apology. I was completely blind to the fact 
that the bignums in the stream (and also in the output list from 
stream-take) were huge, and so the conclusion that "the output list 
from take only needs about 600000 bytes"  (as measured by (time 
(list-copy t))) is of course wrong. With
   (declare (fixnum)(not safe))
the "issue" is gone. Also using stream-ref (see below) instead of 
stream-take, Gambit clearly is showing to be deallocating the stream 
head. (The other observation, that Gambit is seemingly increasingly 
filling up memory after *repeated* runs with bignums and large n's in 
the example of my last mail, might still be an issue, but I would 
have to experiment more to be sure.)

Thanks for this nice scheme system
Christian.


;; -- 8< --- (the mentioned stream-ref function:  )

(define (stream-drop strm k)
   (if (and (##fixnum? k) (##fixnum.>= k 0))
       (let iter ((strm strm) (k k))
         (if (##fixnum.zero? k) strm
	    (let ((p (stream-force strm)))
	      (if (##pair? p)
		  (iter (##cdr p)
			(##fixnum.- k 1))
		  (error "stream-drop: stream too short")))))
       (error "stream-drop: k is not a positive fixnum:" k)))

(define (stream-ref strm i)
   (stream-car (stream-drop strm i)))

;; test with: (time (stream-ref (fib-stream) 350000))
;; (takes a long time, but does not take up memory)



More information about the Gambit-list mailing list