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: Sun, 02 Jan 2022 19:11:02 +0100 Message-ID: References: <878rw1pvcw.fsf@logand.com> <83r19tgqlq.fsf@gnu.org> <87v8z5nmsp.fsf@logand.com> <875yr3krs5.fsf@logand.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7297"; 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:Ah5RqwtDfmnJ4SGmuJlikrfYc5g= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 02 19:12:29 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 1n45LJ-0001kd-C8 for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Jan 2022 19:12:29 +0100 Original-Received: from localhost ([::1]:33008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n45LI-0006Os-96 for ged-emacs-devel@m.gmane-mx.org; Sun, 02 Jan 2022 13:12:28 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n45K4-0004Kj-GP for emacs-devel@gnu.org; Sun, 02 Jan 2022 13:11:12 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]:58826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n45K2-0007Fi-Pf for emacs-devel@gnu.org; Sun, 02 Jan 2022 13:11:12 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1n45K0-0000IZ-S2 for emacs-devel@gnu.org; Sun, 02 Jan 2022 19:11:08 +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:283942 Archived-At: Tomas Hlavaty writes: > On Fri 31 Dec 2021 at 15:23, Rudolf Schlatte wrote: >> 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. > > This is another topic. > > Somehow it seems very controversial. Some even violently oppose the > idea of using gc for non-memory resources but I have not found anybody > yet who would help me to understand real deep pros and cons and let me > form my own opinion without forcing his own. I apologize for derailing the thread a bit, and acknowledge that I did not really engage with your concrete problem (this was also pointed out by Stefan M, thanks for this). That being said, I'll try to express, in one exaggerated sentence, the deep cons of using gc for non-memory resources in the hope that it helps a bit: ”If you rely on the garbage collector to release non-memory resources as a side effect of reclaiming memory, you will run out of resources if you increase the main memory of your system.”