From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: When are unused overlays garbage collected? Date: Wed, 26 May 2021 06:53:42 +0200 Message-ID: <875yz6drjd.fsf@mbork.pl> References: <87v978u3nd.fsf@mbork.pl> <83im38e2qv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34245"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.1.0; emacs 28.0.50 Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 26 06:54:55 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lllZH-0008eo-Dc for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 06:54:55 +0200 Original-Received: from localhost ([::1]:60460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lllZF-0004Qv-Mq for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 26 May 2021 00:54:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lllYV-0004QX-Ce for help-gnu-emacs@gnu.org; Wed, 26 May 2021 00:54:07 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:46476) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lllYN-0006gg-Js; Wed, 26 May 2021 00:54:07 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 28396E6ACD; Wed, 26 May 2021 06:53:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CsDWQ6NTRSht; Wed, 26 May 2021 06:53:46 +0200 (CEST) Original-Received: from localhost (178235147076.dynamic-3-poz-k-0-1-0.vectranet.pl [178.235.147.76]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 4240BE62EA; Wed, 26 May 2021 06:53:46 +0200 (CEST) In-reply-to: <83im38e2qv.fsf@gnu.org> Received-SPF: pass client-ip=195.110.48.8; envelope-from=mbork@mbork.pl; helo=mail.mojserwer.eu X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:130236 Archived-At: On 2021-05-24, at 14:27, Eli Zaretskii wrote: >> From: Marcin Borkowski >> Date: Mon, 24 May 2021 07:00:54 +0200 >>=20 >> --8<---------------cut here---------------start------------->8--- >> The overlay continues to exist as a Lisp object, and its property list >> is unchanged, but it ceases to be attached to the buffer it belonged to, >> and ceases to have any effect on display. >>=20 >> A deleted overlay is not permanently disconnected. You can give it >> a position in a buffer again by calling =E2=80=98move-overlay=E2=80=99. >> --8<---------------cut here---------------end--------------->8--- >>=20 >> So I assume that if I `delete-overlay', it means it cannot be >> necessarily garbage-collected yet. > > Yes, it _can_ be GCed right away, at least in principle. But Emacs > will not necessarily trigger GC right away, so the overlay will not > necessarily be collected immediately, even if it isn't references from > any other variable or structure anymore. I realize that GC might not trigger immediately, of course. 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=E2=80=99s value is # so I assume it was /not/ GCed. >> 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? >> 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'). > > No, overlays-in and overlays-at will not find a deleted overlay. > These functions walk the buffer's overlay list, and a deleted overlay > is unlinked from that list. 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? > Does that answer your questions? (I'm not sure what is exactly your > question, because you didn't describe the context in which this issue > bothered you.) Well, this is one of the many questions that I wanted to have answered for myself while writing my Emacs Lisp book (which I'm not sure I'm allowed to talk about here) - just so that I have a better understanding of overlays (note that I've been using them in my code for quite some time - it turns out that only after you try to explain something, you start to understand it better/appreciate it more/realize you didn't understand it really well...). Best, --=20 Marcin Borkowski http://mbork.pl