[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible Memory Leak with stream-for-each
From: |
Andy Wingo |
Subject: |
Re: Possible Memory Leak with stream-for-each |
Date: |
Tue, 20 Jul 2010 22:36:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
On Mon 19 Jul 2010 20:08, Abhijeet More <address@hidden> writes:
> 1. Can it be confirmed that this is a leak in guile's garbage
> collection?
Hi,
I can confirm this for Guile 1.9/2.0 at least. Gross... The code that I
used was, to first generate a test file:
(with-output-to-file "/tmp/test"
(lambda ()
(let lp ((n 0))
(if (< n 10000000)
(begin
(write '(foo))
(lp (1+ n)))))))
Then execute the following code:
(define stream-null? null?)
(define the-empty-stream '())
(define (stream-car stream) (car stream))
(define (stream-cdr stream) (force (cdr stream)))
(define-syntax cons-stream
(syntax-rules ()
((_ ?car ?cdr) (cons ?car (delay ?cdr)))))
(define (stream-for-each proc s)
(if (not (stream-null? s))
(begin (proc (stream-car s))
(stream-for-each proc (stream-cdr s)))))
(define (port->stream port readproc)
(cons-stream (readproc port) (port->stream port readproc)))
(stream-for-each
identity
(port->stream (open-input-file "/tmp/test") read))
And I see memory usage explode, yes, at the REPL, even if I disable
position recording via (read-disable 'positions).
> 2. Are there any workarounds (for instance doing an explicit "(gc)"
> somewhere in the definitions?
> 3. Any pointers on fixing the underlying issue?
I don't know. Ludovic? :) You have certainly found a bug, though. We
probably won't look into it for 1.8, but we will certainly try to fix it
for 2.0 (soon!).
> 4. I noticed that streams in guile (ice-9 streams) were not
> implemented in the SICP way. In-fact they were implemented in a way
> that makes recursive definitions impossible. Was this intentional?
I don't know TBH. SICP streams do have a problem, amply explored in
http://www.cs.rice.edu/~taha/publications/conference/sml98.pdf; but
beyond that, I don't know.
Perturbedly yours,
Andy
--
http://wingolog.org/
- Possible Memory Leak with stream-for-each, Abhijeet More, 2010/07/19
- Re: Possible Memory Leak with stream-for-each,
Andy Wingo <=
- Re: Possible Memory Leak with stream-for-each, Ludovic Courtès, 2010/07/24
- Re: Possible Memory Leak with stream-for-each, Abhijeet More, 2010/07/24
- Re: Possible Memory Leak with stream-for-each, Abhijeet More, 2010/07/24
- Re: Possible Memory Leak with stream-for-each, Andy Wingo, 2010/07/26
- Re: Possible Memory Leak with stream-for-each, Abhijeet More, 2010/07/29
- Re: Possible Memory Leak with stream-for-each, Andy Wingo, 2010/07/31
- Re: Possible Memory Leak with stream-for-each, Abhijeet More, 2010/07/31