help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When are unused overlays garbage collected?


From: Stefan Monnier
Subject: Re: When are unused overlays garbage collected?
Date: Wed, 26 May 2021 10:48:53 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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

There's been proposals to add a `markers-in` function or
something similar.  The main motivation was to better preserve some
marker's positions when replacing a chunk of text with another.

But the need is not very compelling, and there are some technical
issues, one of them being that internally overlays are contain two
markers, so this would risk exposing those markers, making it possible
for an overlay to have a start and an end in two different buffers.
None of this is terribly difficult to solve, but compared to the
usefulness it just doesn't seem worth the trouble.

>> 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, of course, there's nothing very unusual going here, really: when an
overlay is placed in a buffer, it creates a reference from that buffer
to the overlay, so the overlay is reachable as long as the buffer itself
is reachable.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]