[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
using finalizers
From: |
Tomas Hlavaty |
Subject: |
using finalizers |
Date: |
Thu, 30 Dec 2021 23:43:11 +0100 |
Hi,
I am trying to understand finalizers in Emacs Lisp but I am unable to
triger it.
Here is an example (with lexical-binding):
(defun finito ()
(let ((x '(a b c)))
(letrec ((more (make-finalizer close))
(close (lambda ()
(print "close-resource")
(setq more nil))))
(lambda ()
(when more
(pop x))))))
(setq foo (finito))
(equal '(a b c nil nil) (mapcar (lambda (x) (funcall foo)) '(1 2 3 4 5)))
(setq foo nil)
(garbage-collect)
After garbage collection, I would expect to see close-resource text in
the *Messages* buffer but there is none.
The interface is different from Common Lisp, where make-finalizer
usually expects object and thunk, not thunk only but I guess the problem
lies somewhere else.
What is the expected example usage of finalizers in Emacs Lisp?
How can I verify, that my finalizer works?
Thanks in advance
Tomas
- using finalizers,
Tomas Hlavaty <=