Understanding ESP32 Memory Usage: A Deep Dive into Firmware Size
D/IRAM (Data/Instruction RAM)
D/IRAM (Data/Instruction RAM) is a versatile memory region used to store both data and executable code:
Used stat D/IRAM: 98768 bytes (222528 remain, 30.7% used)
98768 bytes are currently used.
222528 bytes remain free.
30.7% used indicates that nearly a third of this memory is utilized.
This region's efficient usage is vital for the performance of your application, as it directly impacts the CPU's ability to access data and execute code.
.data Section
The .data section holds initialized global and static variables:
.data size: 11112 bytes
11112 bytes are used for these variables.
At startup, the values for these variables are copied from Flash memory to RAM. This ensures that your application has the necessary initial values for its variables.
.bss Section
The .bss section contains uninitialized global and static variables:
.bss size: 18104 bytes
18104 bytes are used for these variables.
Unlike the .data section, the .bss section does not occupy space in the Flash binary; it only takes up RAM when the program runs. The system zeroes this memory at startup.
.text Section
The .text section is where the executable code resides:
.text size: 69552 bytes
69552 bytes are used for the code.
Efficient code management ensures that your firmware's logic fits within the available memory, impacting performance and stability.
Flash Memory
Flash memory is crucial for storing your firmware's executable code and read-only data:
Used Flash size: 736532 bytes
This is the total Flash memory used by the firmware.
Executable Code
.text: 604548 bytes
604548 bytes of Flash are used for storing the executable code.
Read-Only Data
.rodata: 128912 bytes
128912 bytes are used for read-only data such as constants and string literals.
Total Image Size
The Total image size reflects the complete size of your firmware, which may include padding:
Total image size: 817196 bytes (.bin may be padded larger)
817196 bytes is the size of the firmware image.
The binary file (.bin) may be larger due to padding added for alignment or other bootloader requirements.
Memory Regions Breakdown
When we compile and link your ESP32 project, the output provides a detailed breakdown of how memory is allocated. Here’s an example of such a summary
Let's break down what each of these memory sections represents.

