[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When are unused overlays garbage collected?
From: |
Eli Zaretskii |
Subject: |
Re: When are unused overlays garbage collected? |
Date: |
Wed, 26 May 2021 15:34:24 +0300 |
> From: Marcin Borkowski <mbork@mbork.pl>
> Date: Wed, 26 May 2021 07:01:48 +0200
> Cc: help-gnu-emacs@gnu.org
>
> > 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?
I think we don't have markers-in because it isn't needed. overlays-in
is needed when you want to find the next or the previous overlay, or
when you need to know what faces contribute to the appearance of a
character at certain position. There's no such need for markers.
> > 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?
Yes, killing a buffer deletes all of its overlays (and all of its
markers).
Re: When are unused overlays garbage collected?, Stefan Monnier, 2021/05/24