mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-17 03:21:14 +02:00
Updated Avoiding pitfalls (markdown)
@@ -45,13 +45,13 @@ For example, don't do this:
|
||||
|
||||
because the local variable `buffer` will be *removed* from memory when the function `parseArray()` returns, and the `JsonArray&` will point to an invalid location.
|
||||
|
||||
#### 4. Don't reuse the same `StaticJsonBuffer`
|
||||
#### 4. Don't reuse the same `JsonBuffer`
|
||||
|
||||
During is lifetime a `StaticJsonBuffer` growth until it's discarded. If you try to reuse the same instance several time, it will rapidly get full.
|
||||
During is lifetime a `JsonBuffer` growth until it's discarded. If you try to reuse the same instance several time, it will rapidly get full. This is true for both `DynamicJsonBuffer` and `StaticJsonBuffer`.
|
||||
|
||||
For this reason, you should not use a global variable for your `StaticJsonBuffer`. I don't think there is any scenario in which a global `StaticJsonBuffer` would be a valid option.
|
||||
For this reason, **you should not use a global variable** for your `JsonBuffer`. I don't think there is any scenario in which a global `JsonBuffer` would be a valid option.
|
||||
|
||||
The best practice is to declare it in a local scope, so that it's discarded as soon as possible. My advice it to declare it in a function which unique role is to handle the JSON serialization.
|
||||
The best practice is to **declare it in a local scope**, so that it's discarded as soon as possible. My advice it to declare it in a function which unique role is to handle the JSON serialization.
|
||||
|
||||
#### 5. Keep the JSON string in memory long enough
|
||||
|
||||
|
Reference in New Issue
Block a user