From: Joe Wells <jbw@macs.hw.ac.uk>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: bug-gnu-emacs@gnu.org
Subject: Re: frames vs. weak hash tables and garbage collection
Date: Fri, 28 Sep 2007 19:48:22 +0100 [thread overview]
Message-ID: <86lkaqy6bt.fsf@macs.hw.ac.uk> (raw)
In-Reply-To: <jwvy7eqzmiz.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri\, 28 Sep 2007 14\:22\:09 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> The reference from `values' is just due to the fact that you run
>>> `reproduce-bug' from M-: and that its return value contains the frame, so
>>> it's a rather unusual circumstance.
>
>> I'm confused. The frame can only show up in values if it fails to be
>> garbage collected for another reason.
>
> Right. In your case the reason is the recent events array.
>
>> Anyway, although I can see that the recent events array would be
>> enough to cause the problem, I'm not sure it is the only cause.
>
> Could be, but at least it matched the behavior I saw:
> if I hit a key 300 times, set `values' to nil, and call garbage-collect then
> the hash-table entry gets deleted (I modified your test case to make the
> hash-table global).
>
>> (defun reproduce-bug ()
>> [ ... new version of code deleted ... ]
>> ... )
>
> No idea about this one, but it may very well be due to transient effects
> such as the fact that the stack is scanned conservatively, so there may
> still be a spurious pointer to the frame left over somewhere at the time you
> call `garbage-collect'.
It seems it is not the stack. See below.
> Also the sit-for is enough to cause redisplay and execution of process
> filters, but I'm not convinced it's enough to cause the frame events to be
> added to the "recent events array", so maybe these will appear after the
> call to clear-this-command-keys.
Okay. Using a recursive-edit seems to be enough:
(defun reproduce-bug ()
(let ((ht (make-hash-table :weakness 'key)))
(let ((x
(make-frame)
;;(get-buffer-create "xyzzy")
))
(puthash x t ht)
(delete-frame x)
;;(kill-buffer x)
)
;; Give time for various frame related events to be handled, in
;; case this is needed.
(recursive-edit)
;; There may be a reference to the frame in the array of recent
;; events, so we clear this array.
(clear-this-command-keys)
;; In theory, the only reference to the new frame is now the key
;; in the hash table. Because of the weakness, this key should
;; not keep the frame alive.
(garbage-collect)
;; The hash table should now be empty.
(let (l)
(maphash (lambda (k v) (push (cons k v) l)) ht)
l)))
Evaluate (reproduce-bug) and type C-M-c (exit-recursive-edit) in the
recursive edit, and it correctly returns nil.
(By the way, I tried doing
(setq unread-command-events (append (kbd "C-M-c") nil))
just before the recursive edit, but that wasn't enough. It needs to
have real user interaction. I'm curious if there is some purely
programmatic way of simulating the effects of a recursive edit with
only C-M-c typed in it, because this would help in building test
cases.)
Conclusion: There is no bug with garbage collection of deleted
frames, but merely the appearance of a bug, because the recent event
array keeps the frame alive for a while.
Thanks for tracking down the cause of the appearance of a bug!
--
Joe
next prev parent reply other threads:[~2007-09-28 18:48 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-30 1:27 frames vs. weak hash tables and garbage collection Joe Wells
2007-08-30 2:07 ` Eric Hanchrow
2007-08-30 3:00 ` Thien-Thi Nguyen
2007-08-30 3:07 ` Thien-Thi Nguyen
[not found] ` <mailman.47.1188442895.18990.bug-gnu-emacs@gnu.org>
2007-08-31 15:15 ` Joe Wells
2007-08-31 15:42 ` Thien-Thi Nguyen
2007-08-31 15:50 ` Thien-Thi Nguyen
[not found] ` <mailman.116.1188575498.18990.bug-gnu-emacs@gnu.org>
[not found] ` <xnjir6tyj35.fsf@csb.bu.edu>
2007-09-02 2:00 ` Thien-Thi Nguyen
[not found] ` <mailman.115.1188574978.18990.bug-gnu-emacs@gnu.org>
[not found] ` <xnjhcmdyirv.fsf@csb.bu.edu>
2007-09-02 2:13 ` Thien-Thi Nguyen
2007-09-25 23:23 ` Joe Wells
2007-09-27 7:20 ` Glenn Morris
2007-09-27 8:50 ` Thien-Thi Nguyen
[not found] ` <mailman.1408.1190931512.18990.bug-gnu-emacs@gnu.org>
2007-09-28 14:34 ` Stefan Monnier
2007-09-28 14:56 ` Joe Wells
2007-09-28 16:27 ` Stefan Monnier
2007-09-28 16:50 ` Joe Wells
2007-09-28 18:22 ` Stefan Monnier
2007-09-28 18:48 ` Joe Wells [this message]
2007-09-29 16:10 ` Richard Stallman
2007-09-29 16:20 ` Joe Wells
2007-09-29 18:28 ` Stefan Monnier
2007-09-29 19:25 ` Drew Adams
2007-09-30 12:55 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86lkaqy6bt.fsf@macs.hw.ac.uk \
--to=jbw@macs.hw.ac.uk \
--cc=bug-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).