Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

'Reallocating large String(... -> ...)' warning when using WebServer

Open hmueller01 opened this issue 2 years ago • 4 comments

Hi,

since PR #8821 I get this output from ESP8266WebServer:

[String] 'Content-Ty ... ires: -1
': Reallocating large String(140 -> 162 bytes)

It's from this line https://github.com/esp8266/Arduino/blob/be02af0504869e2bf119a013fe8fd6cf5ed8e411/libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h#L433 if sendHeader() is used more than once. Like here: https://github.com/khoih-prog/ESP_WiFiManager_Lite/blob/085afdbd7ccfb7e46b1ed9f1cf5c50be29cc3223/src/ESP_WiFiManager_Lite.h#L2771

Is there something we can do against it?

hmueller01 avatar Feb 27 '23 19:02 hmueller01

Thanks for having revealed an internal misuse of strings. Fixing this is on us.

d-a-v avatar Feb 27 '23 20:02 d-a-v

If you are using the git version of this core, can you try with #8873 ?

(or the unofficial "nightly" alpha release)

d-a-v avatar Mar 01 '23 10:03 d-a-v

As written in #8873 the change in ESP8266WebServer looks good to me.

There is similar issue in ESP8266HTTPClient https://github.com/esp8266/Arduino/blob/6ad9bf3b07ecbe8dd34623c8f81db3b7614cffbf/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp#L820 if you add multiple headers ...

hmueller01 avatar Mar 11 '23 13:03 hmueller01

The output appears also in the published version 3.1.2 when DEBUG_ESP_PORT is enabled even when Debug Level == none.

Example:

[String] 'Content-Ty ... rigin: *
': Reallocating large String(159 -> 183 bytes)
[String] 'Content-Ty ... ep-alive
': Reallocating large String(183 -> 209 bytes)

mathertel avatar Mar 22 '23 11:03 mathertel