[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using finalizers
From: |
Stefan Monnier |
Subject: |
Re: using finalizers |
Date: |
Fri, 31 Dec 2021 11:21:04 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Rudolf Schlatte [2021-12-31 15:23:32] wrote:
> Tomas Hlavaty <tom@logand.com> 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.
Stefan
- Re: using finalizers, (continued)
Re: using finalizers, Eli Zaretskii, 2021/12/31
Re: using finalizers, LdBeth, 2021/12/31