Comments (6)
Hi @Laxilef,
ArduinoJson 7 has a very different memory management strategy which doesn't allow specifying the capacity anymore. I'm honestly quite surprised that someone asked for this after I received so many complaints about the fixed memory allocation of ArduinoJson 6.
JsonDocument
allocates large blocks and only frees on destruction and reallocates in shrinkToFit()
, so it shouldn't create heap fragmentation, at least in regular scenarios. The only place I expect to see a little fragmentation is in deserializeJson()
because it needs to resize buffers for strings.
But what makes you think ArduinoJson 7 increases the heap fragmentation in your program?
Since it has to over-allocate, ArduinoJson 7 may have a peak memory consumption superior to version 6. You can check this with the ArduinoJson Assistant.
Best regards,
Benoit
from arduinojson.
The dynamic memory allocation feature is very convenient! I'm not saying that heap fragmentation is caused by the library :) I'm trying to find the reason.
If I understand correctly, the clear()
method clears the JsonDocument
but doesn't touch the memory pool. And shrinkToFit()
reduces the pool strictly to the necessary size.
Is the memory pool preserved when destroying a JsonDocument
?
I'm wondering whether the memory pool is being reused. For example, I have about 25 methods, each of which creates a JsonDocument ranging in size from 500 to 2000 bytes, at the end of each method the data is serialized and sent to mqtt. And these methods are called one after another. But I'm not using a static JsonDocument
. Each call to one of the methods creates a new JsonDocument
.
from arduinojson.
JsonDocument
's destructor and clear()
both release all the allocated heap memory.
Given all the tests I've run, I'd be very surprised if there were a memory leak in ArduinoJson 7, but we cannot exclude this possibility.
What hardware is this running on?
Can you print the available memory?
from arduinojson.
Thanks!
I'm testing on ESP8266 and ESP32.
I didn’t notice any problems on the ESP32, since there is more memory there than on the ESP8266. I continue to study the problem with memory. And it seems that the problem is not in your library. It looks like these are not really leaks, but heap fragmentation. That is, free heap = 22k, but max free block = 6k. The moment the max free block gets so small, the program crashes.
Although it would be great to try to allocate a pool at startup, for example 2kb. And then work only within this pool: all new JsonDocument will allocate memory only in this pool. Do you think it is possible to do this using a custom allocator?
from arduinojson.
On ArduinoJson 7, JsonDocument
allocates blocks of 1KB, so it should be able to use the remaining heap, even if it's fragmented.
The allocation strategy is very different in v7 and doesn't allow reserving a pool at startup.
In theory, you could do it with a custom allocator, but I doubt it will improve the situation.
from arduinojson.
Ok, thanks for the information! I'll keep watching and let you know if I find something interesting.
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.