From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: When are unused overlays garbage collected? Date: Mon, 24 May 2021 13:07:38 -0400 Message-ID: References: <87v978u3nd.fsf@mbork.pl> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="863"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:ooS6BML7BzpTxdsb4dQDQdBVJCc= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 24 19:19:25 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 1llEEf-000AdU-Lc for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 24 May 2021 19:19:25 +0200 Original-Received: from localhost ([::1]:59210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llEEe-00073u-NN for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 24 May 2021 13:19:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llE3S-0006kS-Su for help-gnu-emacs@gnu.org; Mon, 24 May 2021 13:07:51 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:52320) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llE3Q-000560-5s for help-gnu-emacs@gnu.org; Mon, 24 May 2021 13:07:49 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1llE3N-0004wv-AB for help-gnu-emacs@gnu.org; Mon, 24 May 2021 19:07:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:130187 Archived-At: > 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