JsonDocument dynamic allocation problem
Created by: Leo-C
Hi,
the title not refers to DynamicJsonDocument
, but it refers precisely to dinamic allocation of a JsonDocument
with new
!
My environment is: Platform: ESP32 TTGO IDE: Arduino IDE 1.8.13
The simple code below compile well, but crash at delete
:
#include <Arduino.h>
#include <ArduinoJson.h>
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.println("Mem before: " + String(ESP.getFreeHeap()));
JsonDocument* doc = new DynamicJsonDocument(1024);
delete doc;
Serial.println("Mem after: " + String(ESP.getFreeHeap()));
}
(this is a minimal example for a scenario where I allocate dinamically a JsonDocument
into a function, return a pointer, and only after use, I call destructor in a different scope with delete
in a different scope)
I appreciate any help to understand my error
Many thanks in advance
Leonardo