Chapter 2. API Reference
size_t total_allocated_bytes
Total bytes allocated to data in the heap.
size_t largest_free_block
Size of largest free block in the heap. This is the largest malloc-able size.
size_t minimum_free_bytes
Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size().
size_t allocated_blocks
Number of (variable size) blocks allocated in the heap.
size_t free_blocks
Number of (variable size) free blocks in the heap.
size_t total_blocks
Total number of (variable size) blocks in the heap.
Type Definitions
typedef struct multi_heap_info *multi_heap_handle_t
Opaque handle to a registered heap.
2.6.13 Heap Memory Debugging
Overview
ESP-IDF integrates tools for requesting heap information, detecting heap corruption, and tracing memory leaks. These
can help track down memory-related bugs.
For general information about the heap memory allocator, see the Heap Memory Allocation page.
Heap Information
To obtain information about the state of the heap:
• xPortGetFreeHeapSize() is a FreeRTOS function which returns the number of free bytes in the (data
memory) heap. This is equivalent to calling heap_caps_get_free_size(MALLOC_CAP_8BIT).
• heap_caps_get_free_size() can also be used to return the current free memory for different memory
capabilities.
• heap_caps_get_largest_free_block() can be used to return the largest free block in the heap.
This is the largest single allocation which is currently possible. Tracking this value and comparing to total free
heap allows you to detect heap fragmentation.
• xPortGetMinimumEverFreeHeapSize() and the related heap_caps_get_minimum_free_size()
can be used to track the heap “low water mark”since boot.
• heap_caps_get_info() returns a multi_heap_info_t structure which contains the information
from the above functions, plus some additional heap-specific data (number of allocations, etc.).
• heap_caps_print_heap_info() prints a summary to stdout of the information returned by
heap_caps_get_info().
• heap_caps_dump() and heap_caps_dump_all() will output detailed information about the struc-
ture of each block in the heap. Note that this can be large amount of output.
Heap Corruption Detection
Heap corruption detection allows you to detect various types of heap memory errors:
• Out of bounds writes & buffer overflow.
• Writes to freed memory.
• Reads from freed or uninitialized memory,
Espressif Systems 983
Submit Document Feedback
Release v4.4