[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about memory usage

From: Michał Kondraciuk
Subject: Re: Question about memory usage
Date: Tue, 3 Apr 2018 19:57:34 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 04/03/2018 08:28 AM, Eli Zaretskii wrote:
From: Michał Kondraciuk <address@hidden>
Date: Mon, 2 Apr 2018 13:57:26 +0200

Basically, when I run the sexp below in emacs -Q, Emacs keeps allocating
a lot of memory. In 10 minutes, it goes from 18 MB to over 200 MB.

(while t
      (setq buffer-undo-list nil)
      (insert "a")))

Calling garbage-collect afterwards or even inside the body of the loop
doesn't help (except the loop obviously runs slower, so after 10
minutes, Emacs uses ~100 MB of memory).

What do you mean by "afterwards"?  The while-loop never ends, so
there's no "afterwards" AFAIU.  Am I missing something?

You're right, I meant after I stop the loop with C-g.

To answer your question: yes, I think this is expected, given that you
set buffer-undo-list to nil (what is the purpose of that, btw?).

No purpose, but some external packages display information in a way similar to this sexp, where undo information is also recorded (needlessly):

(with-current-buffer (get-buffer-create "info")
   (let ((inhibit-read-only t))
     (insert "info"))
   (setq buffer-read-only t)
   (display-buffer (current-buffer)))

I tested it in a loop (but also killed the "info" buffer in each iteration) and Emacs also keeps allocating memory, as with (with-temp-buffer (setq buffer-undo-list nil) ...). Obviously normally this isn't a problem because you won't run this code in a loop, but if you leave Emacs open for a long time and run this sexp as part of some command many times, memory can accumulate (I think, it's why I asked if Emacs will finally free this unused memory).

When Emacs ends up requesting more memory from the OS, it usually
doesn't release that memory when it is no longer needed, but keeps it
in the process's address space and reuses it if/when it needs more
But shouldn't Emacs reuse the memory from previous loop iteration instead of allocating it? Also, if the sexp is modified like this, Emacs memory usage is at the same level:

(while t
    (insert "a")
    (setq buffer-undo-list (list (cons (point-min) (point-max))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]