ESP32 minimal heap_caps_print_heap_info() example (PlatformIO/Arduino)
On the ESP32, you can use heap_caps_print_heap_info()
to print information to the serial port about how much memory is free on the heap (plus other details such as the largest free block).
#include <esp_heap_caps.h>
void setup() {
}
void loop() {
heap_caps_print_heap_info(MALLOC_CAP_8BIT);
}
Example output
Heap summary for capabilities 0x00000004:
At 0x3ffb8000 len 6688 free 0 allocated 4404 min_free 0
largest_free_block 0 alloc_blocks 8 free_blocks 0 total_blocks 8
At 0x3ffb0000 len 25480 free 0 allocated 22204 min_free 0
largest_free_block 0 alloc_blocks 70 free_blocks 0 total_blocks 70
At 0x3ffae6e0 len 6192 free 8 allocated 3860 min_free 8
largest_free_block 0 alloc_blocks 10 free_blocks 1 total_blocks 11
At 0x3ffb6388 len 7288 free 0 allocated 4524 min_free 0
largest_free_block 0 alloc_blocks 38 free_blocks 0 total_blocks 38
At 0x3ffb9a20 len 16648 free 8 allocated 13964 min_free 0
largest_free_block 0 alloc_blocks 32 free_blocks 1 total_blocks 33
At 0x3ffcc5d0 len 80432 free 8 allocated 73140 min_free 8
largest_free_block 0 alloc_blocks 320 free_blocks 1 total_blocks 321
At 0x3ffe0440 len 15072 free 0 allocated 12260 min_free 0
largest_free_block 0 alloc_blocks 41 free_blocks 0 total_blocks 41
At 0x3ffe4350 len 113840 free 18440 allocated 90724 min_free 2560
largest_free_block 7796 alloc_blocks 157 free_blocks 12 total_blocks 169
Totals:
free 18464 allocated 225080 min_free 2576 largest_free_block 7796