ESP32 FAQ

ESP32 Memory: RAM, Heap, Stack

// memory · ram · heap · faq

Filed under: ESP32 · Memory · Updated August 2026

How much ram does esp32 have, what PSRAM is for, and why your heap keeps shrinking — no datasheet theater.

How Much RAM Does ESP32 Have?

A classic ESP32 has 520 KB of internal SRAM; your sketch gets roughly 320 KB once Wi-Fi and Bluetooth are running. The rest feeds radio stacks and caches; the S3 has 512 KB. For a real number, read ESP.getFreeHeap() after Wi-Fi joins — on my WROVER-B it settles around 190 KB. That’s the honest answer to how much ram does esp32 have for your program.

What Is PSRAM ESP32?

PSRAM is extra RAM soldered onto the module rather than inside the die — pseudo-static RAM that acts like slow, roomy memory. Classic WROVER modules carry 4 MB; newer S3 modules go up to 8 MB. Search “what is esp32 psram” and every summary agrees: it exists so big buffers (camera frames, audio, web content) don’t eat the internal heap. Layout details: under-the-hood FAQ.

What Is PSRAM in ESP32?

PSRAM in ESP32 terms is an external SPI, QSPI, or octal chip the CPU addresses almost like regular RAM, through the cache. The “almost” matters: access is slower than internal SRAM, so hot code and handlers should stay put. It is optional — WROOM modules have none — and software must enable it before malloc touches it.

How to Use PSRAM ESP32?

Enable it, then allocate from it: Tools → PSRAM → Enabled in Arduino IDE, then ps_malloc() or heap_caps_malloc(MALLOC_CAP_SPIRAM). Plain malloc() and new() ignore PSRAM by default, which feeds half the “PSRAM not working” threads. How to use psram in esp32 arduino sketches in one line: ps_malloc(4096).

How to Know If ESP32 Includes PSRAM?

Read the module name: WROOM means no PSRAM, WROVER means yes; S3 modules encode it in the suffix — N8R8 is 8 MB flash plus 8 MB PSRAM. At runtime, ESP.getPsramSize() returns bytes or zero (WROVER boards report 0 until PSRAM is enabled). Labels on cheap clones lie sometimes; the runtime call doesn’t.

What is the heap, and why does it keep shrinking?

The heap is the pool your program draws from for malloc, strings, and Wi-Fi internals — and it shrinks because those subsystems rarely give memory back. Fragmentation is the sneakier thief: 30 KB free but no 20 KB block exists. Track it with heap_caps_get_free_size(MALLOC_CAP_8BIT).

How do I stop stack overflows?

Stack overflows crash in confusing ways — random resets, garbled strings, a “stack canary” panic. Every FreeRTOS task gets a fixed stack; the Arduino loop task defaults to 8 KB. Raise it in xTaskCreatePinnedToCore(), or move big buffers to the heap — arrays over a few hundred bytes don’t belong on the stack. Panic decoding lives in our debugging FAQ.

Can I Program ESP32 with Python?

Yes — MicroPython gives you a REPL after one firmware flash and is the fastest way to prototype. If you already know how to program esp32 in the Arduino IDE, MicroPython is a second bootloader away. It costs 1–2 MB of flash and a big slice of RAM, and many libraries lack equivalents. Trade-offs are in the getting-started FAQ.

Does PSRAM slow my program down?

It can — SPIRAM is roughly an order of magnitude slower than internal SRAM once cache misses count, though cached reads are fine. Audio buffers, frame buffers, and web assets work great there; hot loops and ISR data don’t. In practice most projects never notice — it depends on your board and workload.

Why does my sketch report less RAM than the datasheet?

Because the 520 KB includes memory the chip itself needs: IRAM for code, cache for flash, and reserved radio space. The board isn’t faulty — trust free heap, not the datasheet; totals shift with SDK version and the docs stay vague about them. Internal RAM is your scarce resource; design around it, or buy PSRAM.

Leave a Reply

Your email address will not be published. Required fields are marked *