all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: npostavs@gmail.com (Noam Postavsky)
Cc: emacs-devel@gnu.org
Subject: Re: [elpa] master b5f4061: Drop forced lambda's from stream (Bug#30626)
Date: Tue, 04 Jun 2019 09:27:09 -0400	[thread overview]
Message-ID: <jwv4l55h4e5.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20190604002519.251AC209A5@vcs0.savannah.gnu.org> (Noam Postavsky's message of "Mon,  3 Jun 2019 20:25:18 -0400 (EDT)")

>     Let the stream id distinguish between forced and unforced stream
>     values.  When the value is forced, replace the lambda with its result.
>     This lets the lambda and anything it references be garbage collected.

Doesn't the same "memory leak" affect thunks?
How 'bout the patch below


        Stefan
        

diff --git a/lisp/emacs-lisp/thunk.el b/lisp/emacs-lisp/thunk.el
index e1370c4591..8d28570dc2 100644
--- a/lisp/emacs-lisp/thunk.el
+++ b/lisp/emacs-lisp/thunk.el
@@ -54,16 +54,15 @@ thunk-delay
   "Delay the evaluation of BODY."
   (declare (debug t))
   (cl-assert lexical-binding)
-  (let ((forced (make-symbol "forced"))
-        (val (make-symbol "val")))
-    `(let (,forced ,val)
-       (lambda (&optional check)
-         (if check
-             ,forced
-           (unless ,forced
-             (setf ,val (progn ,@body))
-             (setf ,forced t))
-           ,val)))))
+  `(let (forced
+         (val (lambda () ,@body)))
+     (lambda (&optional check)
+       (if check
+           forced
+         (unless forced
+           (setf val (funcall val))
+           (setf forced t))
+         val))))
 
 (defun thunk-force (delayed)
   "Force the evaluation of DELAYED.




       reply	other threads:[~2019-06-04 13:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190604002517.28469.52294@vcs0.savannah.gnu.org>
     [not found] ` <20190604002519.251AC209A5@vcs0.savannah.gnu.org>
2019-06-04 13:27   ` Stefan Monnier [this message]
2019-06-04 15:43     ` [elpa] master b5f4061: Drop forced lambda's from stream (Bug#30626) Noam Postavsky
2019-06-04 16:58       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv4l55h4e5.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.