How to Stop Ubuntu from Automatically Closing Inactive Windows

The Aggressive OOM Killer

Linux distributions like Ubuntu are designed to prioritize system stability above all else. If you are running heavily demanding tasks (like compiling a massive codebase or rendering a complex 3D scene) and the system completely runs out of physical RAM and swap space, the kernel invokes the Out-Of-Memory (OOM) Killer. This background process automatically identifies the application consuming the most memory and forcefully closes (kills) it without warning to save the operating system from a hard crash. While this keeps the desktop responsive, it often means your massive, unsaved project is instantly destroyed because it was the biggest resource hog.

Taming the Memory Manager

To prevent sudden data loss and stop Ubuntu from automatically closing massive inactive windows when memory gets tight, you must adjust the OOM score of the specific application or increase your swap space.

The safest way to prevent the OOM killer from triggering is to add more virtual memory (Swap). However, you can also tell the OOM killer to ignore a specific process. First, find the Process ID (PID) of the app you want to protect by opening a terminal and typing top or htop. Note the PID number. You then need to adjust its oom_score_adj value. Type sudo echo -1000 > /proc/[PID]/oom_score_adj (replacing [PID] with your actual number) and press Enter. A score of -1000 makes the process effectively immune to the OOM killer. Be warned: if this protected application continues to leak memory, your entire Ubuntu system will eventually lock up and require a hard reboot.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.