ESP_ERR_NO_MEM (0x101) on the ESP32
An ESP-IDF function could not allocate the memory it needed. The total free heap is often not the problem: the largest free block is.
ESP_ERROR_CHECK failed: esp_err_t 0x101 (ESP_ERR_NO_MEM) at 0x400d2a4f file: "./main/main.c" line 42 func: app_main expression: …
ESP_ERR_NO_MEM (0x101). ESP-IDF's description: Out of memory.
Measure the right numbers
heap_caps_get_free_size(MALLOC_CAP_8BIT): free heap in total.heap_caps_get_largest_free_block(MALLOC_CAP_8BIT): the biggest single allocation that can succeed right now. If this is much smaller than the total, the heap is fragmented.heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT): the lowest the free heap has been since boot.MALLOC_CAP_INTERNALandMALLOC_CAP_DMAfor memory that must be internal or DMA-capable: WiFi, drivers and DMA buffers cannot use PSRAM.
The usual causes
- A leak: the minimum free heap keeps falling over hours or days. Look for allocations without a matching free in code that runs repeatedly, such as HTTP clients and JSON parsing.
- Fragmentation: many allocations of different sizes and lifetimes. Allocate large, long-lived buffers once at startup.
- TLS: each TLS connection needs tens of kilobytes. Two at once can be one too many. See ESP32 TLS memory.
- Internal RAM used up by things that could live in PSRAM on boards that have it.
A leak usually shows up in the field days after shipping. Pinscope records each device's free heap over time, so a slow leak is a falling line before it is a crash: heap and stack monitoring.
Related errors: ESP_ERR_NVS_NO_FREE_PAGES · ESP_ERR_INVALID_STATE · esp_err_t codes. All ESP32 errors: the list. Codes and descriptions from ESP-IDF's headers; behaviour from the API documentation of the functions named. ESP-IDF's Error Handling guide.
More
- Remote access to an ESP32 without TLS: what it measured and what it costs
- Reaching an ESP32 web server from outside its network
- Updating ESP32 firmware over the internet, with rollback
- Guru Meditation Error: decoding the backtrace, and crashes from the field
- Remote logging: ESP_LOG without a serial cable
- Heap and stack monitoring in the field
- An ESP32 behind CGNAT, 4G or Starlink
- TLS memory usage on the ESP32, and how to reduce it
- Sharing an ESP32 sensor page with anyone, without port forwarding
- ArduinoOTA over the internet, with a rollback
- ESP32 remote access compared: port forwarding, ngrok, Cloudflare Tunnel, Tailscale
- esp_http_server slow? The 250 ms delay and the fix
- Before the first ESP32 ships: a field support checklist
- ESP32 exception decoder: a Guru Meditation backtrace to lines, in the browser