From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Abhijeet More Newsgroups: gmane.lisp.guile.user Subject: Possible Memory Leak with stream-for-each Date: Mon, 19 Jul 2010 14:08:45 -0400 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: dough.gmane.org 1279562942 9470 80.91.229.12 (19 Jul 2010 18:09:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 19 Jul 2010 18:09:02 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jul 19 20:09:00 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Oaulr-0001tA-4N for guile-user@m.gmane.org; Mon, 19 Jul 2010 20:08:55 +0200 Original-Received: from localhost ([127.0.0.1]:56107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oaulq-0004Xn-G3 for guile-user@m.gmane.org; Mon, 19 Jul 2010 14:08:54 -0400 Original-Received: from [140.186.70.92] (port=60008 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oaulk-0004WU-NW for guile-user@gnu.org; Mon, 19 Jul 2010 14:08:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oaulj-0004CB-GV for guile-user@gnu.org; Mon, 19 Jul 2010 14:08:48 -0400 Original-Received: from mail-gw0-f41.google.com ([74.125.83.41]:46251) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oaulj-0004BY-E4 for guile-user@gnu.org; Mon, 19 Jul 2010 14:08:47 -0400 Original-Received: by gwb1 with SMTP id 1so2682036gwb.0 for ; Mon, 19 Jul 2010 11:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=6ZD2vnP0YX3kKOP4XdDl/zMmaZIeC/DaZiQMzkYCTGg=; b=mI9iilK5ApmhN4Vh9lMqmutLNb/7IOmEIghK3Kcm9xlmhv2k2nfF++oDxqingwXSPi ThZkH77SJ0LQizN9EpEdBCg0MlzvrrxAW3LIaFKfl1S3t1lTlo+7uul6nMQoLNfpGs0E 4XF7nPNALaFwssDlDvEp1w0/z7ELML+tO14H8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=G9YsILmcKupne3ljU/B/RCM5uzfB2I8YyyhMLgy90AIALXUHn2RtekvIPtDt9qmBIj hJyVElsHuRhr0IR6+QshKHgpGeZG5Vgl5fVI+NihC0r653ajY5DBuv1CsgnpJWW4GR71 GEXNW1C3zsMFpHw4LEU4ef+TIqtNbdNpxBKBY= Original-Received: by 10.224.65.197 with SMTP id k5mr4431687qai.52.1279562925725; Mon, 19 Jul 2010 11:08:45 -0700 (PDT) Original-Received: by 10.229.228.210 with HTTP; Mon, 19 Jul 2010 11:08:45 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7995 Archived-At: Hi All, I've been trying to use streams as defined in SICP using guile. A little googling showed that an implementation had already been suggested here: http://lists.gnu.org/archive/html/guile-user/2001-04/msg00220.html However, when I use this to iterate through the stream I see that guile's memory utilization keeps growing until the iteration is complete . I'm using guile 1.6.8 (also tested 1.8.7) on linux. I observe the memory utilization under top. I tried the same thing with plt-scheme/racket and it did not show a similar leak i.e .the memory growth was capped at a certain point during the iteration. It did not grow beyond that point. >From a little more googling, it appears that a similar memory leak has been discussed before but that investigation was not completed. Here is the thread: http://sources.redhat.com/ml/guile/2000-03/msg00568.html So my questions are: 1. Can it be confirmed that this is a leak in guile's garbage collection? 2. Are there any workarounds (for instance doing an explicit "(gc)" somewhere in the definitions? 3. Any pointers on fixing the underlying issue? 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? Some code to illustrate what I'm trying to do: Simply print all s-expressions in a file to another as follows : (let* ((outport (open-output-file ))) (stream-for-each (lambda (x) (pretty-print x outport)) (port->stream (open-input-file ) read))) where port->stream is: (define (port->stream port readproc) (cons-stream (readproc port) (port->stream port readproc))) (defmacro cons-stream (a b) `(cons ,a (delay ,b))) (define stream-null? null?) (define the-empty-stream '()) (define (stream-car stream) (car stream)) (define (stream-cdr stream) (force (cdr stream))) (define (stream-for-each proc s) (if (not (stream-null? s)) (begin (proc (stream-car s)) (stream-for-each proc (stream-cdr s))))) I get the same behavior with the following definition: (define-syntax cons-stream (syntax-rules () ((_ ?car ?cdr) (cons ?car (delay ?cdr))))) Thanks Abhijeet