ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

String handling causes - 'Reallocating large String' warnings

Open neutralvibes opened this issue 2 years ago • 1 comments

  • framework-arduinoespressif8266 @ 3.30102.0 (3.1.2)

Warnings for reallocating strings, caused by repeated concatenation which can lead to fragmentation are now flagged.

The WebResponses.cpp file does it here

String AsyncWebServerResponse::_assembleHead(uint8_t version){
  if(version){
    addHeader("Accept-Ranges","none");
    if(_chunked)
      addHeader("Transfer-Encoding","chunked");
  }
  String out = String();

It then goes on to append various things to String variable out.

To remedy this, adding out.reserve(200); just after the variable definition seems to handle it.

neutralvibes avatar Mar 24 '23 13:03 neutralvibes

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 18 '23 13:06 stale[bot]