From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.user Subject: Re: Possible Memory Leak with stream-for-each Date: Tue, 20 Jul 2010 22:36:46 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1279658052 19660 80.91.229.12 (20 Jul 2010 20:34:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 20 Jul 2010 20:34:12 +0000 (UTC) Cc: guile-user@gnu.org To: Abhijeet More Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Jul 20 22:34:11 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 1ObJVz-0004LF-2g for guile-user@m.gmane.org; Tue, 20 Jul 2010 22:34:11 +0200 Original-Received: from localhost ([127.0.0.1]:57560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ObJVy-0003HL-ED for guile-user@m.gmane.org; Tue, 20 Jul 2010 16:34:10 -0400 Original-Received: from [140.186.70.92] (port=39611 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ObJVt-0003HE-KP for guile-user@gnu.org; Tue, 20 Jul 2010 16:34:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ObJVs-0005Rp-6x for guile-user@gnu.org; Tue, 20 Jul 2010 16:34:05 -0400 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:34105 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ObJVs-0005Rd-54 for guile-user@gnu.org; Tue, 20 Jul 2010 16:34:04 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 08D75C63E3; Tue, 20 Jul 2010 16:34:03 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=14YyQyDzRvlK+mc8UeA3t8KgEw4=; b=m8wb6I 8+aIbsnQFGzGH2lbSQjBZrIYpEkcarjnDjdy886l/N/o9ALPRKKx8XgElKdvlhBZ ZtqaNUhiWzVfBO2N+WthXKCVYbiYW9SNp7YNehxXujVrt/xk1B2kHmvbnA7alE9t A4LMnMO/y/biA3agObdFgmT7E6KjKoG9sduJo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=lGmBHFWSeElKKlID6/HvyDUK/DAjeFWR dM9VuXEdXLp+z671FGGXy5xfhblxGsMzqHyVEY19DbHCmtjoxM1BuBk+QpF9XhA2 no50MjCEQYBuL/w5bqZfR8rjsA/hdbvpH7AjmTi+q54PMVbgGxAo5xlnaEE90NeF DpB9/VSXDmE= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 625D5C63E1; Tue, 20 Jul 2010 16:34:01 -0400 (EDT) Original-Received: from unquote.localdomain (unknown [81.39.161.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 67611C63DF; Tue, 20 Jul 2010 16:33:59 -0400 (EDT) In-Reply-To: (Abhijeet More's message of "Mon, 19 Jul 2010 14:08:45 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: 215C3116-943E-11DF-8BAD-9056EE7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) 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:7996 Archived-At: 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: (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/