fork: Cannot allocate memory / ENOMEM
The kernel refused a memory allocation — RAM and swap are exhausted, or overcommit/cgroup limits block it.
Cannot allocate memoryfork: Cannot allocate memoryOSError: [Errno 12] Cannot allocate memory Meaning
Unlike the OOM killer (which kills a process), this fails the allocation: new processes can’t fork, commands fail. Small VPSs without swap, memory leaks, or a container memory limit cause it.
Common causes
- RAM full and no swap
- Memory leak in a long-running process
- vm.overcommit_memory=2 strict accounting
- Container/cgroup memory limit
⚡ Quick fix
- Find the biggest processes: ps aux --sort=-%mem | head
- Add swap on small servers
- Fix the leak or raise the limit
Detailed fix by platform
Linux
- bash
free -h ps aux --sort=-%mem | head sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
How to diagnose
- Memory — free -h
- Top users — ps sorted by memory
- Limits — cgroup/container limits, sysctl vm.overcommit_memory
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 0xC0000005 The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
Most viewed in Linux
- System has not been booted with systemd System has not been booted with systemd as init system (PID 1). Can't operate.
- Repository does not have a Release file E: The repository '...' does not have a Release file
- Start request repeated too quickly systemd: Start request repeated too quickly / service hit its start limit
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026