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)
- Filtering large arrays of objects HOT 4
- deserializeJson from HTTP result in EmptyInput error HOT 3
- best way to create a sub document HOT 6
- Callback-based filter HOT 1
- Adding entry in JsonObject using File object causes corrupted JSON HOT 1
- Initial serializing HOT 7
- `doc[var]` doesn't work when `var` contains a string
- JsonArray.add(JsonObject) adds partial JsonObject when the JsonDocument is full HOT 6
- ArduinoJson.h: No such file or directory HOT 3
- JsonVariant tests false for both a value that doesn't exist and for a value that is zero HOT 7
- How do i create JSON array of objects using ArduinoJson library. HOT 1
- Identifying JsonVariant type of a deserialized document HOT 4
- Example code results in compiler error: no match for 'operator+=' HOT 3
- Passing JsonDocument by reference HOT 4
- In Memory Deserialization HOT 4
- v7 equivalent of validateJson HOT 2
- conversion from ‘ArduinoJson::V704HB42::detail::enable_if<true, ArduinoJson::V704HB42::JsonVariantConst>::type’ {aka ‘ArduinoJson::V704HB42::JsonVariantConst’} to ‘ArduinoJson::V704HB42::JsonDocument’ is ambiguous HOT 1
- Assertion `poolIndex < count_' failed HOT 1
- Maximum string length of 13 characters HOT 2
- V6 Documentation ArduinoJson PubSubClient with StreamUtils 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.