unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Garbage collect and buffer-undo-list
@ 2021-03-13 18:17 Yuan Fu
  2021-03-13 19:01 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Yuan Fu @ 2021-03-13 18:17 UTC (permalink / raw)
  To: emacs-devel

I know the garbage collector trims buffer-undo-list. Does it collect the cons cell if there are other references to that object (other than buffer-undo-list)?

I tried this:

(setq last1 (last buffer-undo-list))
(garbage-collect)

After the garbage collection, the entry referred by last1 is not in buffer-undo-list anymore, but still accessible by last1. That seems to support my theory.

Yuan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Garbage collect and buffer-undo-list
  2021-03-13 18:17 Garbage collect and buffer-undo-list Yuan Fu
@ 2021-03-13 19:01 ` Stefan Monnier
  2021-03-13 19:16   ` Yuan Fu
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2021-03-13 19:01 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> I know the garbage collector trims buffer-undo-list. Does it collect the
> cons cell if there are other references to that object (other than
> buffer-undo-list)?

No, it can't.

If you want to keep a reference to some of those cons-cells but still
want the GC to collect them when the undo-log is trimmed, then you need
to use a weak reference.  We don't currently have plain "weak
references" in ELisp, but we do have hash-tables whose keys and/or
values can be weak references (that's what I used in
`undo-equiv-table`).


        Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Garbage collect and buffer-undo-list
  2021-03-13 19:01 ` Stefan Monnier
@ 2021-03-13 19:16   ` Yuan Fu
  0 siblings, 0 replies; 3+ messages in thread
From: Yuan Fu @ 2021-03-13 19:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel



> On Mar 13, 2021, at 2:01 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>> I know the garbage collector trims buffer-undo-list. Does it collect the
>> cons cell if there are other references to that object (other than
>> buffer-undo-list)?
> 
> No, it can't.
> 
> If you want to keep a reference to some of those cons-cells but still
> want the GC to collect them when the undo-log is trimmed, then you need
> to use a weak reference.  We don't currently have plain "weak
> references" in ELisp, but we do have hash-tables whose keys and/or
> values can be weak references (that's what I used in
> `undo-equiv-table`).
> 

That’s cool, I do want the referenced object to survive. Thanks!

Yuan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-13 19:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-13 18:17 Garbage collect and buffer-undo-list Yuan Fu
2021-03-13 19:01 ` Stefan Monnier
2021-03-13 19:16   ` Yuan Fu

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).