emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using finalizers


From: Rudolf Schlatte
Subject: Re: using finalizers
Date: Sun, 02 Jan 2022 19:11:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)

Tomas Hlavaty <tom@logand.com> writes:

> On Fri 31 Dec 2021 at 15:23, Rudolf Schlatte <rudi@constantly.at> 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.”




reply via email to

[Prev in Thread] Current Thread [Next in Thread]