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: Marcin Borkowski
Subject: Re: When are unused overlays garbage collected?
Date: Thu, 27 May 2021 18:26:26 +0200
User-agent: mu4e 1.1.0; emacs 28.0.50

On 2021-05-26, at 16:48, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

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

I see.

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

Right, I didn't say that it's unusual - I only wanted to clarify that
I don't need to e.g. bother with `remove-overlays' before killing the
buffer (unless I keep a reference to some of them, of course).

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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