Why is my emacs crashing? Answer: bad garbage collection
Table of Contents
Content
Periodically emacs crashes; I spent a long time debugging, which was really difficult because it was only reproducible by crashing my system. It turns out to be because of garbage collection. Other theory is that it is somehow due to Firefox.
Previously tried, ruled out
- EXWM. No, it crashed with Gnome, too
- Popups (esp in browser).
- Too many Firefox windows
- Too much text on the screen at once. But it has crashed in one-screen setups, too
- Stack overflow from programs that are doing logging manually.
- Perhaps it’s company idle delay? (disabled after last crash)
ANSWER: I had disabled garbage collection
;; Defer garbage collection further back in the startup process
;;(setq gc-cons-threshold most-positive-fixnum) ;; unchecked, this disables garbage collection causing emacs to crash at high-use moments
(setq gc-cons-threshold (* 2 800000)) ;; documentation recommended doubling it. Those are bytes.
I had disabled garbage collection as part of my attempts to optimize, borrowing code I didn’t understand. Crucially, I had left out the part of the code that restored the GC after startup.
This answer came from part of a chat on Mastodon.
Learned:
- Try to understand code before you copy-paste
- Garbage collection is important
- Some optimization just isn’t worth it.