Description

JsonArrayConst::memoryUsage() returns the number of bytes used by the array pointed by the JsonArrayConst.

Unlike JsonDocument::memoryUsage(), the result doesn’t include leaked memory.

Signature

size_t memoryUsage() const;

Example

char json[] = "[1,2,3]";
StaticJsonDocument<200> doc;
deserializeJson(doc, json);
doc.remove(2); // remove last element to show the effect of a leak

JsonArrayConst array = doc.as<JsonArray>();

Serial.println(array.memoryUsage());  // 16 on AVR
Serial.println(doc.memoryUsage());    // 24 on AVR

See also

Global warming stripes by Professor Ed Hawkins (University of Reading)