Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1480
Closed
Open
Issue created Jan 26, 2021 by Administrator@rootContributor

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

Assignee
Assign to
Time tracking