JsonDocument::clear() clears the JsonDocument and releases all the memory from the memory pool.

Unlike JsonArray::clear() and JsonObject::clear(), this function releases the memory from the memory pool; therefore, it doesn’t cause a memory leak.

This function resets the memory pool but doesn’t destroy it. The memory pool is still present in memory but is empty. If you want to release memory held by the memory pull, you must destroy the JsonDocument.

If you use the library as intended (see the examples and the book), you don’t need to call this function.

You don’t need to call JsonDocument::clear():

These functions already clear the memory pool, so you don’t need to call JsonDocument::clear().

Every reference (JsonArray, JsonObject, or JsonVariant) acquired before calling clear() is invalidated.


void clear();

See also