Comments (6)
It's true that DynamicJsonBuffer
uses dynamic allocation for its content.
But the class itself is not intended to be dynamically allocated.
Indeed it's designed to avoid that.
You never write new DynamicJsonBuffer()
.
So you never write delete myJsonBuffer
.
So the destructor is always statically called.
Therefore it's still not relevant to make it virtual.
And anyway, I bet that if you make it virtual without changing the base class, you'll trigger another warning.
I don't manage to reproduce the warning on older version of the compiler.
Can you try to add a pragma?
from arduinojson.
I'm sorry I tested on many compilers, including GCC 4.9, but I cannot reproduce this warning.
from arduinojson.
@bblanchon I am getting this issue, and I don't know that I agree with the assertion that you never new the JsonBuffer.
In my case, I am allocating the buffer and storing the pointer and building up a message, perhaps over several function calls or loops.
Once the message is built and written, the buffer needs to be 'released' as you explicitly say don't share or re-use the buffer.
Thus, after saving the json message, I delete the buffer and set the pointer to nullptr.
Before building a new json object
if (jsonBuffer == nullptr) {
jsonBuffer = new DynamicJsonBuffer();
}
Build the object root
JsonObject & root = (*jsonBuffer).createObject();
Later on after finishing with the object root
if (jsonBuffer != nullptr) {
jsonBuffer->clear();
delete jsonBuffer;
jsonBuffer = nullptr;
}
Note that this is done in a class where there can be multiple instances.
Maybe this isn't the best approach, but it certainly seems to work as expected and fulfills my requirements, but if there is another/better way to deal with this I will certainly look at it.
I don't have any memory leaks or other issues and have plenty of space to work with when using a Cortex M4+ type device.
I am not sure the reason you don't have virtual destructors but I found that the compiler warnings (and most documentation say they are actually rather more than warnings) go away if you make the base class have a virtual destructor.
In JsonBufferBase.hpp
protected:
virtual ~JsonBufferBase() {}
from arduinojson.
Hi @CZEMacLeod,
Why do you use new
and delete
?
from arduinojson.
As I explained in the previous message, I have a process that runs through a number of stages, and adds data to the json message at each stage. Once the message is complete (after many times through loop() and calling to different subroutines) it gets saved to SD and sent and then a new message is started.
The scope of the buffer and root object are global, not local and need to be deleted at the end of each message and newed at the beginning of the next.
from arduinojson.
I strongly recommend making the buffer local to the loop.
If you believe that this is impossible, just call JsonBuffer::clear()
Regards,
Benoit
from arduinojson.
Related Issues (20)
- Lint error ovl_no_viable_subscript has occured HOT 2
- Cleaning HTML Chuking Answer at the Custom Reader class for getting filtered JsonDocument HOT 1
- Return JsonDocument from class methods HOT 2
- Question - Access JSON data variables in nested arrays HOT 5
- Problem whith a JSON from Firefox to my ESP8266 HOT 3
- Capped Allocator HOT 4
- fatal error: ArduinoJson/Variant/VariantRefBase.hpp: No such file or directory HOT 1
- Example on ArduinoJson website crashes at runtime HOT 1
- ArduinoJson 7.1.0 Compile error [ invalid use of array with unspecified bounds ] HOT 2
- Missing links to specific types in the API reference HOT 1
- Queuing ArduinoJson objects HOT 3
- Deallocator problem (probably) on ESP32-WROVER-E HOT 3
- Compile errors with new IDE?
- Custom reader: readBytes method is not required? HOT 1
- 'struct SpiRamAllocatorST' has no member named 'reallocate'; did you mean 'deallocate'? HOT 5
- Some trouble using variables as element names in JsonDocument HOT 4
- cppcheck: failed to expand 'ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE' HOT 3
- containsValue() method HOT 2
- Keep a JsonDocument in PSRAM - Container HOT 3
- File deserialization crash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.