From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.bugs Subject: Re: weak key hash versus display Date: Thu, 30 Jan 2003 10:27:31 +0100 Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Message-ID: References: <877kcn5yqc.fsf@zip.com.au> Reply-To: djurfeldt@nada.kth.se NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1043918787 5487 80.91.224.249 (30 Jan 2003 09:26:27 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 30 Jan 2003 09:26:27 +0000 (UTC) Cc: djurfeldt@nada.kth.se Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18eAxk-0001QA-00 for ; Thu, 30 Jan 2003 10:26:24 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18eAzC-0003Dl-02 for guile-bugs@m.gmane.org; Thu, 30 Jan 2003 04:27:54 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18eAz6-0003AB-00 for bug-guile@gnu.org; Thu, 30 Jan 2003 04:27:48 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18eAz4-000391-00 for bug-guile@gnu.org; Thu, 30 Jan 2003 04:27:48 -0500 Original-Received: from kvast.blakulla.net ([213.212.20.77]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18eAz4-0002xi-00 for bug-guile@gnu.org; Thu, 30 Jan 2003 04:27:46 -0500 Original-Received: from barbara.blakulla.net ([213.212.21.238] helo=linnaeus) by kvast.blakulla.net with esmtp (Exim 3.36 #1 (Debian)) id 18eAyt-0000jU-00; Thu, 30 Jan 2003 10:27:35 +0100 Original-Received: from mdj by linnaeus with local (Exim 3.36 #1 (Debian)) id 18eAyp-0006nG-00; Thu, 30 Jan 2003 10:27:31 +0100 Original-To: Kevin Ryde In-Reply-To: <877kcn5yqc.fsf@zip.com.au> (Kevin Ryde's message of "Thu, 30 Jan 2003 09:21:15 +1000") User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu) Original-cc: bug-guile@gnu.org X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Bug reports for GUILE, GNU's Ubiquitous Extension Language List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.bugs:642 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.bugs:642 Kevin Ryde writes: > In guile 1.6.1 or the cvs on a recent i386 debian, I noticed that > doing a display of a weak key hash table can seemingly prevent a key > from being garbage collected. For instance > > (define h (make-weak-key-hash-table 7)) > > (define k "mykey") > (hash-set! h (string-copy k) 12345) > > (display (hash-ref h k)) (newline) > (display h) (newline) > (gc) > (display (hash-ref h k)) (newline) > > run with "guile -s foo.scm" produces > > 12345 > #wh(() () () () () ((mykey . 12345)) ()) > 12345 > > whereas I might have expected the gc to have collected the entry just > set, making the second hash-ref give #f rather than 12345. This is > what happens if the (display h) is not present. And if you keep (display h) but add (display ), hash-ref will give #f again. The reason is that in order to avoid infinite loops due to circular data-structures print functions need to keep track of printed references. These are stored in a "print-state" attached to the port. After displaying h, the print-state contains the reference to the pair (mykey . 12345) which protects it from GC. We should probably replace this vector with a weak vector, or (perhaps more efficient) clear the references from the vector. > I don't really know if this is a bug, or ignorance on my part, but it > seemed more than a little strange. Well, it's not really a bug. The Guile GC doesn't make any guarantees that objects will get GC:d. For example, if the C stack happens to contain an integer which happens to coincide with a reference on the heap, that object won't get GC:d. A conservative GC only behaves nicely in a statisticial sense. Thanks for your observation. Best regards, Mikael Djurfeldt _______________________________________________ Bug-guile mailing list Bug-guile@gnu.org http://mail.gnu.org/mailman/listinfo/bug-guile