[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When are unused overlays garbage collected?
From: |
Marcin Borkowski |
Subject: |
Re: When are unused overlays garbage collected? |
Date: |
Wed, 26 May 2021 07:01:48 +0200 |
User-agent: |
mu4e 1.1.0; emacs 28.0.50 |
On 2021-05-24, at 19:07, Stefan Monnier via Users list for the GNU Emacs text
editor <help-gnu-emacs@gnu.org> wrote:
>> 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). This would make sense, because even if
>> there is no variable bound to an overlay which is not deleted, you can
>> still get a reference to it using any of the overlay-finding functions
>> (`overlays-at' or `overlays-in').
>
> Sounds right, yes. `delete-overlay` just disconnects the overlay from
> the buffer in which it was placed. As long as an overlay is placed in
> a buffer, then it is still reachable (via internal variables inside the
> buffer, and via `overlays-at' or `overlays-in') and it can have visible
> effects on screen.
Thanks!
> Markers share some of their implementation with overlays, but because
> markers do not affect the display and because there is nothing
> corresponding to `overlays-at' or `overlays-in', Emacs goes through the
> trouble of GC'ing those markers which are still reachable via the
> buffer's internal variables (its list of markers) as long as they're not
> reachable some other way, of course.
Thanks, too, this is pretty interesting. I assume one possible reason
for not having `markers-in' (analogous to `overlays-in') is that an
overlay (even without any variable pointing to it, IOW, a "name" for it)
has some "semantics" (properties), so it can be "guessed" what it is
for; for markers, we would only know that "someone wanted to remember
this position, but we have no idea why/what for", so why even bother
keeping it? (Technically, there is also the insertion type, but that
doesn't tell much, either.)
> So it's OK to create markers are then forget about them, but it's not
> OK to create overlays and then forget about them: you need to manually
> `delete-overlay` when you're done with them otherwise they'll accumulate
> in the buffer.
And that is probably the most important takeaway here - but it raises
another question. If I create an overlay in some buffer, keep no
references to it, and then kill the buffer - is the overlay eligible for
GC? (Again, I performed an experiment, and the results suggest that its
state is similar to what happen after `delete-overlay', so I assume
yes.)
TIA,
--
Marcin Borkowski
http://mbork.pl
- Re: When are unused overlays garbage collected?, (continued)
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/24
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/26
- Re: When are unused overlays garbage collected?, Marcin Borkowski, 2021/05/27
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/27
- Re: When are unused overlays garbage collected?, Marcin Borkowski, 2021/05/28
Re: When are unused overlays garbage collected?, Stefan Monnier, 2021/05/24