【问题标题】:When does Emacs Lisp's lexical-let leak memory?Emacs Lisp 的 lexical-let 什么时候会泄露内存?
【发布时间】:2012-08-06 23:51:27
【问题描述】:

我读到了 lexical-let's memory leak,例如这里: Are there any problems with lexical-let or other cl-macros??? - Users list for the GNU Emacs text editor - ArchiveOrange

上面写着:

"请注意,与 lexical-let 绑定的变量永远不会被释放,即使 如果它们从未使用过。试试

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

然后看着它吃掉记忆。”

但我认为这段代码消耗内存只是因为循环生成的列表增加了。 所以,我写了一些 elisp 代码来检查它何时发生,但我找不到泄漏的例子。

这就是我执行以下代码时内存随时间增长的方式。

(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))))

看起来没有泄漏。

在此处查看更多示例: https://gist.github.com/1703325

添加:这是第一个示例消耗内存的方式。正如我所说,我认为这是一个神器。

【问题讨论】:

标签: emacs memory-leaks elisp


【解决方案1】:

我刚刚在emacs-devel

When does Emacs Lisp's lexical-let leak memory? 所以......真的吗,“与 lexical-let 绑定的变量永远不会 释放,即使它们从未使用过”?

我不知道。当然,这段代码不是没有bug的,但我不知道 遇到此类错误的任何具体案例。

-- Re: lexical-let cause memory leaks?

【讨论】:

    猜你喜欢
    • 2011-05-13
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 2012-05-04
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    相关资源
    最近更新 更多