From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Hlavaty Newsgroups: gmane.emacs.devel Subject: Re: using finalizers Date: Sat, 01 Jan 2022 18:37:30 +0100 Message-ID: <87h7anl5lx.fsf@logand.com> References: <878rw1pvcw.fsf@logand.com> <83r19tgqlq.fsf@gnu.org> <87v8z5nmsp.fsf@logand.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36255"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier , Rudolf Schlatte Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 01 18:38:22 2022 Return-path: Envelope-to: ged-emacs-devel@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 1n3iKj-0009AD-Ul for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 18:38:21 +0100 Original-Received: from localhost ([::1]:44992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3iKi-0002aP-Ds for ged-emacs-devel@m.gmane-mx.org; Sat, 01 Jan 2022 12:38:20 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3iK4-0001ud-Mg for emacs-devel@gnu.org; Sat, 01 Jan 2022 12:37:40 -0500 Original-Received: from logand.com ([37.48.87.44]:54474) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3iK2-0007Kx-VP for emacs-devel@gnu.org; Sat, 01 Jan 2022 12:37:40 -0500 Original-Received: by logand.com (Postfix, from userid 1001) id B21E019EC87; Sat, 1 Jan 2022 18:37:31 +0100 (CET) X-Mailer: emacs 27.2 (via feedmail 11-beta-1 I) In-Reply-To: Received-SPF: pass client-ip=37.48.87.44; envelope-from=tom@logand.com; helo=logand.com X-Spam_score_int: 0 X-Spam_score: -0.0 X-Spam_bar: / X-Spam_report: (-0.0 / 5.0 requ) SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:283804 Archived-At: On Fri 31 Dec 2021 at 11:21, Stefan Monnier wrote: > Rudolf Schlatte [2021-12-31 15:23:32] wrote: > >> Tomas Hlavaty writes: >>> >>> I can see these cases where garbage collection might not do its job: >>> >>> 1. imprecise gc >>> >>> 2. program exit or abort >>> >>> 3. a leak to be fixed >> >> 4. the gc is generational and the object is in an old generation >> >> 5. the gc is incremental and didn't get around to the object yet >> >> ... etc >> >> I'm sure you knew this already, but in general, using gc for non-memory >> resource management (e.g., "please close this file when this Lisp object >> is GCed") is not a good idea--depending on the GC behavior, you'll run >> out of file handles or whatnot. The RAII pattern in C++ >> deterministically calls a destructor when a stack-allocated object goes >> out of scope; in Lisp, the various `with-foo' macros serve the same >> purpose. > > But the context here is a "bug report" about a finalizer not being > called and it seemed pretty clear that the call to `garbage-collect` was > just there to try and make the bug more apparent, not because the real > ELisp code relies on the finalizer being called right at the first call > to `garbage-collect` after the object became unreachable. yes, that was the original issue