help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Question about memory usage


From: Óscar Fuentes
Subject: Re: Question about memory usage
Date: Tue, 03 Apr 2018 04:16:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Michał Kondraciuk <k.michal@zoho.com> writes:

> Hello,
>
> Originally I wanted to report this to bug-gnu-emacs, but it's so basic
> that I thought I'd ask here instead.
>
> 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
>   (with-temp-buffer
>     (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).
> So I want to know if this behavior is expected for some reason? Does
> Emacs reuse this memory somehow (to make future allocations faster)? I
> tested on newest master and 25.3 and the behavior is the same.

Maybe it is related to this (emphasis mine):

 -- User Option: gc-cons-threshold
     The value of this variable is the number of bytes of storage that
     must be allocated for Lisp objects after one garbage collection in
     order to trigger another garbage collection.  You can use the
     result returned by ‘garbage-collect’ to get an information about
     size of the particular object type; space allocated to the contents
     of buffers does not count.  NOTE THAT THE SUBSEQUENT GARBAGE
     COLLECTION DOES NOT HAPPEN IMMEDIATELY WHEN THE THRESHOLD IS
     EXHAUSTED, BUT ONLY THE NEXT TIME THE LISP INTERPRETER IS CALLED.

As your example runs in one call of the interpreter, the gargage
collector is never kicked.

Curiously, if a call to garbage-collect is put inside the loop, memory
usage also grows, although slowly.

As for returning the memory to the OS, I've seen Emacs doing that for
very large objects. The rest is simply marked as free.




reply via email to

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