From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Rudolf Schlatte Newsgroups: gmane.emacs.devel Subject: Re: using finalizers Date: Fri, 31 Dec 2021 15:23:32 +0100 Message-ID: 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="619"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin) To: emacs-devel@gnu.org Cancel-Lock: sha1:p3FCcD/2rWsX2zjWLmLcbmRl2k4= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 31 15:24:45 2021 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 1n3Ipo-000ATi-Jg for ged-emacs-devel@m.gmane-mx.org; Fri, 31 Dec 2021 15:24:44 +0100 Original-Received: from localhost ([::1]:60772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3Ipn-0002ku-7k for ged-emacs-devel@m.gmane-mx.org; Fri, 31 Dec 2021 09:24:43 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3IpA-00026H-E4 for emacs-devel@gnu.org; Fri, 31 Dec 2021 09:24:04 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]:53866) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3Ip8-0007iW-HN for emacs-devel@gnu.org; Fri, 31 Dec 2021 09:24:04 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1n3Ip5-0009YZ-9W for emacs-devel@gnu.org; Fri, 31 Dec 2021 15:23:59 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 2 X-Spam_score: 0.2 X-Spam_bar: / X-Spam_report: (0.2 / 5.0 requ) HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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:283742 Archived-At: 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.