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: Mon, 24 May 2021 13:07:38 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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

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.

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.


        Stefan




reply via email to

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