From: Marcin Borkowski <mbork@mbork.pl>
To: Eli Zaretskii <eliz@gnu.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: When are unused overlays garbage collected?
Date: Thu, 27 May 2021 18:20:46 +0200 [thread overview]
Message-ID: <87y2c0cfmp.fsf@mbork.pl> (raw)
In-Reply-To: <83zgwhad9i.fsf@gnu.org>
On 2021-05-26, at 14:30, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Marcin Borkowski <mbork@mbork.pl>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 26 May 2021 06:53:42 +0200
>>
>> But what would happen if I (delete-overlay my-overlay), then it gets
>> garbage collected, and then I (move-overlay my-overlay ...)?
>>
>> I just performed a simple experiment - I manually created an overlay in
>> a temporary buffer, bound a variable to it, deleted it, and called
>> (garbage-collect) - and C-h v'ing that variable still said:
>>
>> aqq’s value is #<overlay in no buffer>
>>
>> so I assume it was /not/ GCed.
>
> It wasn't GCed because it was referenced from a variable.
Stupid me, of course.
>> >> My guess would be that if the overlay is "deleted" (so it is not
>> >> attached to any buffer, either by means of `delete-overlay' or when its
>> >> buffer is killed) /and/ it can't be referenced from Elisp (e.g., there
>> >> is no variable bound to it).
>> >
>> > That's not entirely true. An overlay (like any other Lisp object)
>> > that was deleted will not be collected as long as some variable
>> > _actually_references_ it. That could be a Lisp variable or a C
>> > variable not exposed to Lisp. The difference between what I wrote and
>> > what you wrote is that the reference must actually exist, not only be
>> > possible.
>>
>> I am not sure if I grasp that difference. Can you provide an example of
>> a situation when an object does not have an "actual reference" but still
>> "can be referenced"? Do you mean e.g. it being an element of a list
>> bound to some variable?
>
> No, that's not the essence of the difference. You said, above, "it
> can't be referenced from Lisp". My point is that "can't" doesn't cut
> it, because an object can be GCed even if it _can_ be referenced.
> What matters is that it _is_not_ referenced, even though it _can_be_.
>
> IOW, any object can potentially be referenced by some variable, but GC
> only avoids recycling an object if some other object actually (not
> potentially) references it. The GC's "mark" phase scans all the live
> Lisp objects and marks any other objects referenced by those live
> objects, recursively. Any marked object will not be recycled by the
> "sweep" phase.
I think we misunderstood each other. By "can't be referenced from Lisp"
I meant "there was no object - like a variable - referencing it". IOW,
no possible Lisp code could get me a reference to that overlay. So we
agree, we just used words in a different way.
>> Well, I meant something different - an overlay that is "live" in some
>> buffer, but no variable is bound to it. Such an overlay /can/ be
>> referenced with `overlays-in' / `overlays-at', so obviously cannot be
>> GCed, right?
>
> No live overlay in a live buffer will ever be GCed, because when GC
> marks live buffers, it also marks the overlays in that buffer by
> walking the linked list of the buffer's overlays.
Yes, that was what I meant. Thanks.
--
Marcin Borkowski
http://mbork.pl
next prev parent reply other threads:[~2021-05-27 16:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-24 5:00 When are unused overlays garbage collected? Marcin Borkowski
2021-05-24 5:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-24 6:33 ` Marcin Borkowski
2021-05-24 12:27 ` Eli Zaretskii
2021-05-26 4:53 ` Marcin Borkowski
2021-05-26 7:23 ` tomas
2021-05-26 15:36 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-26 16:52 ` tomas
2021-05-26 12:30 ` Eli Zaretskii
2021-05-27 16:20 ` Marcin Borkowski [this message]
2021-05-27 16:41 ` Eli Zaretskii
2021-05-28 19:38 ` Marcin Borkowski
2021-05-24 17:07 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-26 5:01 ` Marcin Borkowski
2021-05-26 12:34 ` Eli Zaretskii
2021-05-27 16:23 ` Marcin Borkowski
2021-05-26 14:48 ` Stefan Monnier
2021-05-27 16:26 ` Marcin Borkowski
2021-05-27 21:42 ` Stefan Monnier
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=87y2c0cfmp.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/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.
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).