Giter Club home page Giter Club logo

Comments (6)

bblanchon avatar bblanchon commented on May 21, 2024

A memory leak is very unlikely if you use StaticJsonBuffer because there is no dynamic memory allocation.
However, you need to understand that StaticJsonBuffer holds the JSON tokens until it is out of scope, it's the way it is supposed to work.
You probably just have to move the declaration of the StaticJsonBuffer inside the loop, so as to reduce the scope of the variable to just were it's needed.
If it doesn't work, please copy/paste the code here.

from arduinojson.

Tomega3 avatar Tomega3 commented on May 21, 2024

Hi,

Thanks for the email.

I am attaching my test sketch

/***********************************
Possible memory leak or issue during parse:
Look at the messages on serial monitor which say:
Serial.print(F("json buffer contents before parse: "));
Serial.println(json);
// copy the char array to a temp buffer
// because it appears that ArduinoJson lib somehow truncates it
snprintf_P(espbuffer, (sizeof(espbuffer)), PSTR("%s"), json);
Serial.print(F("json buffer contents in temp buffer before parse: "));
and
Serial.print(F("json temp buffer contents after parse: "));
Serial.println(espbuffer);

after the parse the espbuffers' contents appear to be truncated.

also:
with StaticJsonBuffer<300> jsonBuffer;
declared as a global variable, the parse reports failure after the
4th or 5th time thru the loop.

with it declared inside the parse function ( parseTestDataJSON)
no reported parse failures are seen but the
espbuffer is still appears to be truncated.

My concern is that the buffer espbuffer appears to be truncated after
the parse.

I am running arduino 1.06 on an arduino uno r3

I also tried it on an ESPToy from rayshobbys which has a esp8266 wifi module
that I connect to a weatherdata website to data from
you can find it here:: http://rayshobby.net/?p=10156

On this board my pc appears to slow way down when running the test
sketch and my GetWifiWeatherData sketch

Thanks again,

Let me know what you find.

Tom

On 2/23/2015 3:37 PM, Benoît Blanchon wrote:

A memory leak is very unlikely if you use |StaticJsonBuffer| because
there is no dynamic memory allocation.
However, you need to understand that |StaticJsonBuffer| holds the JSON
tokens until it is out of scope, it's the way it is supposed to work.
You probably just have to move the declaration of the
|StaticJsonBuffer| inside the loop, so as to reduce the scope of the
variable to just were it's needed.
If it doesn't work, please copy/paste the code here.


Reply to this email directly or view it on GitHub
#49 (comment).

from arduinojson.

bblanchon avatar bblanchon commented on May 21, 2024

Hi Tom,

Can you please create a gist with the complete .ino file?

Also, please have a look at the documentation:

Regards,
Benoit

from arduinojson.

Tomega3 avatar Tomega3 commented on May 21, 2024

Hi Benoit,

I created a Gist of my test file.
see
https://gist.github.com/Tomega3/2f9e208f61da69edafbf

I have read the memory model and the avoiding pitfalls

I hope this helps

Thanks again,

Tom

On 2/24/2015 4:38 AM, Benoît Blanchon wrote:

Hi Tom,

Can you please create a gist https://gist.github.com/ with the
complete |.ino| file?

Also, please have a look at the documentation:

Regards,
Benoit


Reply to this email directly or view it on GitHub
#49 (comment).

from arduinojson.

bblanchon avatar bblanchon commented on May 21, 2024

I'm sorry, I think I overlooked your sentence:

My concern is that the buffer espbuffer appears to be truncated after
the parse.

This is an expected behavior, please read carefully Avoiding pitfalls, section 6:

Indeed, the parser modifies the string for two reasons:

  • it inserts \0 to terminate substrings,
  • it translate escaped characters like \n or \t.

This is how the library works.
It's done this way to avoid memory copy.
If you do need a copy of the original string, you need to make a copy in your program.

from arduinojson.

Tomega3 avatar Tomega3 commented on May 21, 2024

Thank you very much for the info.

If you want to close and or remove the issue I posted please do so.

Thanks again,

Tom

On 2/24/2015 8:40 AM, Benoît Blanchon wrote:

I'm sorry, I think I overlooked your sentence:

My concern is that the buffer espbuffer appears to be truncated after
the parse.

This is an expected behavior, please read carefully Avoiding pitfalls,
section 6
https://arduinojson.org/doc/pitfalls/#6-make-sure-the-string-isnt-read-only:

Indeed, the parser modifies the string for two reasons:

  * it inserts \0 to terminate substrings,
  * it translate escaped characters like \n or \t.

This is how the library works.
It's done this way to avoid memory copy.
If you do need a copy of the original string, you need to make a copy
in your program.


Reply to this email directly or view it on GitHub
#49 (comment).

from arduinojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.