Updated FAQ (markdown)

Benoît Blanchon
2015-10-16 21:52:56 +02:00
parent b2954bd1d5
commit f6d3420182

18
FAQ.md

@@ -42,4 +42,20 @@ See also: [issue #101](https://github.com/bblanchon/ArduinoJson/issues/101) and
Some platforms need some time to initialize the serial port.
In that case, you need to add a `delay()` in the setup.
See issue [#112](https://github.com/bblanchon/ArduinoJson/issues/112).
See issue [#112](https://github.com/bblanchon/ArduinoJson/issues/112).
### I found a memory leak in the library!
This is very unlikely. You're probably using the library incorrectly.
The typical problem comes from reusing a `JsonBuffer` several time.
Each time you call `parseArray()`, `parseObject()`, `createArray()` and `createObject()`, you consume memory in the `JsonBuffer`.
To avoid running out of memory, you should discard unused data as soon as possible.
The recommended practice is to do the JSON handling in a dedicated function, with a local `JsonBuffer` that will be automatically reclaimed when the function exits.
This means that you cannot return a `JsonArray` or a `JsonObject` from that function, because they would contains dangling pointers to what used to be the `JsonBuffer`.
Instead, you should convert the content of the `JsonArray` to a custom array or `vector`; or the content of the `JsonObject` to your own data structure.
This seems like a constrain, but remember that you're programming for an embedded platform with very limited resources; and that requires special techniques.
A positive side effect of following this recommandation is that the code is safe and memory efficient. It also encourage the separation of responsibilities: the function is only in charge of the JSON serialization an no specific JSON data leaks elsewhere is the program.