all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: When are unused overlays garbage collected?
Date: Wed, 26 May 2021 15:30:17 +0300	[thread overview]
Message-ID: <83zgwhad9i.fsf@gnu.org> (raw)
In-Reply-To: <875yz6drjd.fsf@mbork.pl> (message from Marcin Borkowski on Wed,  26 May 2021 06:53:42 +0200)

> From: Marcin Borkowski <mbork@mbork.pl>
> Cc: help-gnu-emacs@gnu.org
> Date: Wed, 26 May 2021 06:53:42 +0200
> 
> But what would happen if I (delete-overlay my-overlay), then it gets
> garbage collected, and then I (move-overlay my-overlay ...)?
> 
> I just performed a simple experiment - I manually created an overlay in
> a temporary buffer, bound a variable to it, deleted it, and called
> (garbage-collect) - and C-h v'ing that variable still said:
> 
> aqq’s value is #<overlay in no buffer>
> 
> so I assume it was /not/ GCed.

It wasn't GCed because it was referenced from a variable.

> >> 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).
> >
> > That's not entirely true.  An overlay (like any other Lisp object)
> > that was deleted will not be collected as long as some variable
> > _actually_references_ it.  That could be a Lisp variable or a C
> > variable not exposed to Lisp.  The difference between what I wrote and
> > what you wrote is that the reference must actually exist, not only be
> > possible.
> 
> I am not sure if I grasp that difference.  Can you provide an example of
> a situation when an object does not have an "actual reference" but still
> "can be referenced"?  Do you mean e.g. it being an element of a list
> bound to some variable?

No, that's not the essence of the difference.  You said, above, "it
can't be referenced from Lisp".  My point is that "can't" doesn't cut
it, because an object can be GCed even if it _can_ be referenced.
What matters is that it _is_not_ referenced, even though it _can_be_.

IOW, any object can potentially be referenced by some variable, but GC
only avoids recycling an object if some other object actually (not
potentially) references it.  The GC's "mark" phase scans all the live
Lisp objects and marks any other objects referenced by those live
objects, recursively.  Any marked object will not be recycled by the
"sweep" phase.

> Well, I meant something different - an overlay that is "live" in some
> buffer, but no variable is bound to it.  Such an overlay /can/ be
> referenced with `overlays-in' / `overlays-at', so obviously cannot be
> GCed, right?

No live overlay in a live buffer will ever be GCed, because when GC
marks live buffers, it also marks the overlays in that buffer by
walking the linked list of the buffer's overlays.



  parent reply	other threads:[~2021-05-26 12:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24  5:00 When are unused overlays garbage collected? Marcin Borkowski
2021-05-24  5:05 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-24  6:33   ` Marcin Borkowski
2021-05-24 12:27 ` Eli Zaretskii
2021-05-26  4:53   ` Marcin Borkowski
2021-05-26  7:23     ` tomas
2021-05-26 15:36       ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-26 16:52         ` tomas
2021-05-26 12:30     ` Eli Zaretskii [this message]
2021-05-27 16:20       ` Marcin Borkowski
2021-05-27 16:41         ` Eli Zaretskii
2021-05-28 19:38           ` Marcin Borkowski
2021-05-24 17:07 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-05-26  5:01   ` Marcin Borkowski
2021-05-26 12:34     ` Eli Zaretskii
2021-05-27 16:23       ` Marcin Borkowski
2021-05-26 14:48     ` Stefan Monnier
2021-05-27 16:26       ` Marcin Borkowski
2021-05-27 21:42         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83zgwhad9i.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.