There's a serious problem with the String lib

That is the one that is here,

It appears that the String::valueOf functions return a malloc'ed pointer and they will cause a serious memory leak if you use any of them in a loop. The returned object should be a String object so the normal destructor will free the memory. Of course that's assuming you made the mod to include a destructor. Perhaps someone should remove that file until it works.



There is a fix in there. The author is aware of the issue and I too hope that they update it soon ;)

This is a different problem with the same library. I knew about that one. There are some undocumented methods in the String library, at least one of which returns a malloc'ed pointer with no way to free it automatically.

Try looping on this:

Serial.println(String::valueOf(45, DEC)); You'll run out of memory shortly because the static String::valueOf returns a character pointer.

The way to avoid the problem is to do

char *buf = String::valueOf(45,DEC); Serial.println(buf); free(buf);

Or something similar.

Incidently the valueOf method here is backwards from the same function found in java and elsewhere. Jim.