From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tristan Colgate Newsgroups: gmane.lisp.guile.user Subject: Re: Possible Memory Leak with stream-for-each Date: Wed, 21 Jul 2010 08:00:56 +0100 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1279695693 15956 80.91.229.12 (21 Jul 2010 07:01:33 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 21 Jul 2010 07:01:33 +0000 (UTC) Cc: guile-user@gnu.org To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 21 09:01:30 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 1ObTJ3-000758-G7 for guile-user@m.gmane.org; Wed, 21 Jul 2010 09:01:29 +0200 Original-Received: from localhost ([127.0.0.1]:48744 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ObTJ2-0000sn-Ds for guile-user@m.gmane.org; Wed, 21 Jul 2010 03:01:28 -0400 Original-Received: from [140.186.70.92] (port=34277 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ObTIa-0000sg-Ez for guile-user@gnu.org; Wed, 21 Jul 2010 03:01:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ObTIY-0007Rd-OL for guile-user@gnu.org; Wed, 21 Jul 2010 03:01:00 -0400 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:35604) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ObTIY-0007RU-Iy for guile-user@gnu.org; Wed, 21 Jul 2010 03:00:58 -0400 Original-Received: by wwb31 with SMTP id 31so12896wwb.30 for ; Wed, 21 Jul 2010 00:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=QKmP1DbSVVu241gE3Dn2nLPk7u6L1uimne4/nS/JazU=; b=BGfWhtG+CNRpLEK+pN7EWrxTQ4DcK5ZsFJ6XFqpM4o9pXzyN5KhG1TRSTqFWgqKQop Jwy2slrh83USs4iH2uWqlY6eJhnJ9NidEaEqIOJp0KCFgmqm2fnTLyM8EDOASJ00G9gm MV17VJGD5ZEcs6SX5rbi5QLfBaBACHgyRjDG8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Erif4t0uv14NhdT2s5iLYnU3bf5ONYSSpNsz9AGlsImKboVybWw5fjaNSADJxo+Qvz L/Tj4S4KugD7Zdd0jl8HSdem5YC6RR167f2eHRZ4wQx+hu9RX8FBkSgO7XcPXF15t/Qm 6RF3a6gk9M45lU1b8ZboSbkqdq2Uhcj9eK1eU= Original-Received: by 10.227.157.13 with SMTP id z13mr6540091wbw.184.1279695656417; Wed, 21 Jul 2010 00:00:56 -0700 (PDT) Original-Received: by 10.216.165.138 with HTTP; Wed, 21 Jul 2010 00:00:56 -0700 (PDT) In-Reply-To: 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:7997 Archived-At: FWIW, the code in srfi-41 now works out of the box (thanks to some recent r6rs library fixes), with the exception of all the negative unit tests, due to some exception handling issue I didn't really look at. I don't know if it still shows the memory leak though. On 20 July 2010 21:36, Andy Wingo wrote: > On Mon 19 Jul 2010 20:08, Abhijeet More 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: > > =A0(with-output-to-file "/tmp/test" > =A0 =A0(lambda () > =A0 =A0 =A0(let lp ((n 0)) > =A0 =A0 =A0 =A0(if (< n 10000000) > =A0 =A0 =A0 =A0 =A0 =A0(begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0(write '(foo)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(lp (1+ n))))))) > > Then execute the following code: > > =A0(define stream-null? null?) > =A0(define the-empty-stream '()) > =A0(define (stream-car stream) (car stream)) > =A0(define (stream-cdr stream) (force (cdr stream))) > =A0(define-syntax cons-stream > =A0 =A0(syntax-rules () > =A0 =A0 =A0((_ ?car ?cdr) (cons ?car (delay ?cdr))))) > > =A0(define (stream-for-each proc s) > =A0 =A0(if (not (stream-null? s)) > =A0 =A0 =A0 =A0(begin (proc (stream-car s)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (stream-for-each proc (stream-cdr s))))) > > =A0(define (port->stream port readproc) > =A0 =A0(cons-stream (readproc port) (port->stream port readproc))) > > =A0(stream-for-each > =A0 identity > =A0 (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/ > > --=20 Tristan Colgate-McFarlane ---- =A0 "You can get all your daily vitamins from 52 pints of guiness, and a glass of milk"