ch11ng / exwm

Emacs X Window Manager
2.85k stars 134 forks source link

Detecting memory leaks #633

Closed TatriX closed 5 years ago

TatriX commented 5 years ago

My Emacs with EXWM slowly leaks memory.

while (true) { ps -h -p `pidof emacs` -O rss | awk '{print $2;}' | tee emacs.log; sleep 1 }

2019-08-27-135925_1447x1021_scrot

Any advices on how can I find what is leaking memory?

GNU Emacs 27.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.10) of 2019-08-23
EXWM commit d63dc6a
TatriX commented 5 years ago

If I run the same Emacs configuration under awesome WM, it doesn't leak. It seems that every time I switch workspace ~1Mb of memory is leaked.

ch11ng commented 5 years ago

I do notice increasing memory usage here, but not after switching workspace. The cause is not clear to me. Now that you can reproduce this issue reliably, please take a took at various variables/functions described in (info "Garbage Collection") which show some internal statistics.

TatriX commented 5 years ago

Will do, thanks!

TatriX commented 5 years ago

BTW, running (garbage-collect) freezes my EXWM session.

TatriX commented 5 years ago

It seems that the reason why it's eating so much memory in my case is this:

;; Disable GC for startup. It will be restored in after-init-hook.
(setq gc-cons-threshold most-positive-fixnum)
(add-hook 'after-init-hook
          (lambda ()
              (setq gc-cons-threshold 800000))
ch11ng commented 5 years ago

But isn't gc-cons-threshold restored eventually?

TatriX commented 5 years ago

It is in after-init-hook. But for some reason collections do not happen afterwards. After I've removed that piece of code from my init file it became much better. Still sometimes Emacs's memory usage slowly grows to a bigger numbers. I will investigate it a bit more and if I find anything, I'll reopen this issue.

TatriX commented 5 years ago

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=37006