【发布时间】: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
添加:这是第一个示例消耗内存的方式。正如我所说,我认为这是一个神器。
【问题讨论】:
-
FWIW 这是
help-gnu-emacs上的帖子的原始存档页面,没有广告:lists.gnu.org/archive/html/help-gnu-emacs/2010-12/msg00141.html -
emacs devel 比 SO 更适合这类问题
-
此外,Freenode 上的#emacs 频道可能是提出此类问题的好地方。
-
@JonO 谢谢。从现在开始我会尝试使用正式版。
-
谢谢@Tom。正如你所建议的,我发现有人刚刚在 emacs-devel 中回答了这个问题:lists.gnu.org/archive/html/emacs-devel/2012-01/msg00939.html。
标签: emacs memory-leaks elisp