emacs-devel
[Top][All Lists]
Advanced

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

Re: using finalizers


From: Tomas Hlavaty
Subject: Re: using finalizers
Date: Sat, 01 Jan 2022 18:58:01 +0100

On Fri 31 Dec 2021 at 14:27, Eli Zaretskii <eliz@gnu.org> wrote:
> That does happen, but you seem to expect more: you expect that the
> object is collected as soon as you do something in Lisp to break the
> binding between the object and the variable that was bound to it.

No, that's not what I expect.  I even said that.  What I meant is that I
did not expect some other code not under my control to keep references
to the object forever preventing gc to run the finalizer eventually,
which is how I understood your reply.  I know at least one Lisp which
does keeps extra unexpected references to particular kind of objects
preventing finalizers to run, so that kind of behaviour would not be
unheard of, but I see it as a bug and hope that Emacs does not have that
issue.

On another note, I see that finalizers are rarely used and tested:

./test/src/alloc-tests.el33:  (should (equal (type-of (make-finalizer nil)) 
'finalizer)))
./lisp/emacs-lisp/generator.el642:                      (make-finalizer

For example the cps-generate-evaluator function has 70 lines and it is
not obvious to me, that the use of finalizer is not buggy.

Do you have an advice, how are programmers supposed to test finalizers?

My original issue did not run the finalizer because of a bug in my use
of letrec.  Unless there is a good way to actually trigger the
finalizer, there is no good way to test such code paths.  Or shall the
programmers just hope for the best?



reply via email to

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