12

I read about lexical-let's memory leak, for example here: Are there any problems with lexical-let or other cl-macros??? - Users list for the GNU Emacs text editor - ArchiveOrange

It says:

"Note that variables bound with lexical-let are never released, even if they are never used. Try

(loop for i from 1 to 100000 collect (lexical-let ((x i)) '()))

and watch it eat memory."

But I think this code eats memory just because the list made by loop grows. So, I wrote a few elisp codes to check when it occurs but I could not find a example of the leak.

This is how memory grows with time when I execute the code below.

lambda-in-let.el

(require 'cl)

(defvar num-loop-1 30)
(defvar num-loop-2 100000)

(loop for i from 1 to num-loop-1 do
      (loop for j from 1 to num-loop-2 collect
            (lexical-let ((x `(,i ,j))) (lambda () x))))

It looks like there is no leak.

See more examples here: https://gist.github.com/1703325

ADDED: This is how the first example eats memory. As I said, I think it is an artifact.

lambda-in-let.el

Community
  • 1
  • 1
tkf
  • 2,990
  • 18
  • 32
  • FWIW here is the original archive page for the thread on `help-gnu-emacs`, without ads: http://lists.gnu.org/archive/html/help-gnu-emacs/2010-12/msg00141.html –  Jan 30 '12 at 10:58
  • 2
    [emacs devel](http://news.gmane.org/gmane.emacs.devel) is a better place for this kind of question than SO – Tom Jan 30 '12 at 19:26
  • Also, #emacs channel on Freenode could be a good place to ask a question of this kind. – vpit3833 Jan 31 '12 at 02:26
  • @JonO Thanks. I wil try use the official version from now on. – tkf Jan 31 '12 at 16:43
  • Thanks @Tom. As you suggested, I find that somebody just answered the question in emacs-devel: http://lists.gnu.org/archive/html/emacs-devel/2012-01/msg00939.html. – tkf Jan 31 '12 at 16:43
  • @vpit3833 Thanks. I don't use IRC but will try next time I have this kind of question. – tkf Jan 31 '12 at 16:45

1 Answers1

2

I just found this in emacs-devel:

When does Emacs Lisp's lexical-let leak memory? So... Is it true, that "variables bound with lexical-let are never released, even if they are never used"?

Not that I know. Of course, this code is not bug-free, but I don't know of any concrete case that bumps into such a bug.

-- Re: lexical-let cause memory leaks?

Community
  • 1
  • 1
tkf
  • 2,990
  • 18
  • 32