Emacs on macOS: Unraveling a Memory Leak Mystery

2025-07-31

The author has long struggled with performance issues in Emacs on macOS: ever-increasing memory usage, eventually leading to freezes. After investigation, the root cause was found to be in the way `[NSApp run]` is invoked, resulting in massive memory allocation and deallocation, especially pronounced on high-performance hardware and high-DPI displays. The interaction between macOS's event handling and Emacs' efficient resource management leads to caching of useless resources, culminating in memory leaks. While a complete fix is difficult, the author proposes a potential solution: rewriting macOS-specific code in Swift, leveraging its more efficient memory management and asynchronous support to improve Emacs' performance on macOS.

Read more
Development