Out of memory

Linux SystemMemory ErrorCommonLast updated: June 29, 2026Tested on:Ubuntu 22.04 LTSBash Shell v5.1June 2026

This error occurs when the system resources cannot allocate more memory, or when an application exceeds its allocated heap memory constraints.

Out of memory Quick Fix⏱️ Est. Fix Time: 3 minutes

Usually happens because:

  • Physical RAM limits and virtual swap blocks are full
  • Application process exceeded runtime heap constraints limit
  • Code contains memory leaks accumulating allocations over time

🔍 Quick Checklist:

What is Out of memory?

The 'Out of memory' error (ENOMEM) occurs when a process requests virtual or physical memory allocation from the operating system kernel, but the system has exhausted its memory resources and swap space. This error also occurs at the application level (like in Java, Node.js, or Python) when the program's runtime engine exceeds its pre-configured maximum heap memory limits.

Common Causes

  • Physical RAM and swap space exhaustion: The host server is running too many concurrent processes or has insufficient memory.
  • Application heap limit exceeded: The application runtime (e.g. V8 engine or JVM) hits its predefined ceiling limit (e.g. FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory).
  • Memory leak bugs: Software code holds references to unused memory, causing memory consumption to grow until depletion.
CauseFrequency
Application runtime heap limit constraint⭐⭐⭐⭐⭐
Physical system RAM and swap depletion⭐⭐⭐⭐
Code logic memory leaks (e.g. unclosed event listeners)⭐⭐⭐

Common Mistakes

  • Increasing application heap size limits on a host server that lacks free physical memory, leading to heavy page swapping or OOM-killer interventions.
  • Forgetting to release large objects inside JavaScript arrays or event listeners, leading to memory leaks that eventually bypass any heap expansion limits.

How to Fix

1Increase process heap limit: Pass custom runtime parameters to allocate more memory (e.g. 'NODE_OPTIONS="--max-old-space-size=4096"' or '-Xmx4g').
2Add system swap space: Configure a swap partition or swap file to act as memory overflow cache.
3Track and fix memory leaks: Use memory profile tracing utilities (like Chrome DevTools, heap dumps, or leak-detectors) to find memory leaks.

Linux Operations & Verification

Increase default V8 heap limits by setting the old space size option globally or inline.

Node.js Heap Expansion Example
# Inline configuration (increases heap limit to 4GB)
$ node --max-old-space-size=4096 index.js

# Or configure env globally
$ export NODE_OPTIONS="--max-old-space-size=4096"

Platform Specific Fixes

Check current physical RAM usage details inside Linux console shells.

Linux Config
# Display memory details in human-readable megabytes/gigabytes
free -h

Best Practices

  • Avoid loading complete database datasets directly into system memory; utilize streaming tools (like Node.js streams or database cursors).
  • Deploy regular memory profiling audits during development stages using heap snapshot trackers.

Frequently Asked Questions (FAQ)

Q: What is ENOMEM?

ENOMEM is the low-level POSIX error code returned by system calls (like malloc) when memory cannot be allocated.

Q: How do I fix 'JavaScript heap out of memory' in Node.js?

By default, Node limits heap usage to around 1.5GB. Increase it by setting the '--max-old-space-size' parameter: 'node --max-old-space-size=4096 script.js'.

Q: How do I check current memory usage in Linux?

Run 'free -h' to see total, used, and free physical memory and swap.

Q: Why is swap useful?

Swap space is a dedicated area on a hard drive that acts as virtual RAM when physical memory is full, preventing immediate Out of Memory crashes.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error