Refreshing a web-page hangs after few times I'm using a Nucleo F429ZI board and I wrote a sketch that enables a simple web-server:

#include &lt;LwIP.h&gt;
#include &lt;STM32Ethernet.h&gt;

const int WEB_PORT = 80;
EthernetServer server(WEB_PORT);
char buffer[1024];

void setup() 
{
    Serial.begin(115200);
    // define variables
    Ethernet.begin(localIP, netmask, dns, gateway);
    server.begin();
}

void loop() 
{
    processServer();
}

void processServer()
{
  String readString; 
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        readString += c; 

        if (c == '\n')
        {
          if (readString.startsWith("GET"))
          {
            readString.remove(0, 4);
            int pos = readString.indexOf(' ');
            String path = readString.substring(0, pos);

            if (path == "/status") pageStatus(client);
            break;
          }
        }
      }
    }
    delay(1);
    client.stop();
  }
}

void pageStatus(EthernetClient client)
{
    sectionHeader(client, 2);
    client.println("&lt;html&gt;");
    client.println("&lt;style&gt;table{font-family: verdana, sans-serif;border-collapse: collapse;width: 30%;}");
    client.println("td, th{border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even)");
    client.println("{background-color: #dddddd;}&lt;/style&gt;");
    client.println("&lt;table&gt;");
    client.println("&lt;tr&gt;&lt;th&gt;Servo&lt;/th&gt;&lt;th&gt;Position&lt;/th&gt;&lt;th&gt;Running&lt;/th&gt;&lt;th&gt;Initialized&lt;/th&gt;&lt;/tr&gt;");

    for (int i = 0; i &lt; getParamUInt8(P_SERVO_SIZE); i++) 
    {
        sprintf(buffer, "&lt;tr&gt;&lt;td&gt;%u&lt;/td&gt;&lt;td&gt;%d&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;/tr&gt;", i + 1, (int16_t) _servo[i].current, _servo[i].ended ? "NO" : "YES", _servo[i].initialized ? "YES" : "NO" );
        client.println(buffer);
    }
    client.println("&lt;/table&gt;");

    client.println("&lt;br&gt;&lt;hr&gt;&lt;br&gt;");

    client.println("&lt;table&gt;");
    client.println("&lt;tr&gt;&lt;th&gt;Led&lt;/th&gt;&lt;th&gt;PWM&lt;/th&gt;&lt;th&gt;Running&lt;/th&gt;&lt;/tr&gt;");

    for (int i = 0; i &lt; getParamUInt8(P_LED_SIZE); i++) 
    {
        sprintf(buffer, "&lt;tr&gt;&lt;td&gt;%u&lt;/td&gt;&lt;td&gt;%d&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;/tr&gt;", i + 1, (int16_t) _led[i].pwm, _led[i].ended ? "NO" : "YES");
        client.println(buffer);
    }
    client.println("&lt;/table&gt;");

    client.println("&lt;br&gt;&lt;hr&gt;&lt;br&gt;");

    client.println("&lt;table&gt;");
    client.println("&lt;tr&gt;&lt;th&gt;Stepper&lt;/th&gt;&lt;th&gt;Position&lt;/th&gt;&lt;th&gt;Running&lt;/th&gt;&lt;/tr&gt;");

    for (int i = 0; i &lt; getParamUInt8(P_STEPPER_SIZE); i++) 
    {
        sprintf(buffer, "&lt;tr&gt;&lt;td&gt;%u&lt;/td&gt;&lt;td&gt;%d&lt;/td&gt;&lt;td&gt;%s&lt;/td&gt;&lt;/tr&gt;", i + 1, (int16_t) _stepper[i].stepper.getCurrentPositionInMillimeters(), _stepper[i].stepper.motionComplete() ? "NO" : "YES");
        client.println(buffer);
    }
    client.println("&lt;/table&gt;");
    client.println("&lt;/html&gt;");
}

void sectionHeader(EthernetClient client, int refresh)
{
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println("Connection: close");
    if (refresh) client.println("Refresh: 2"); 
    client.println();
    client.println("&lt;!DOCTYPE HTML&gt;");
}


As you can see in the sectionHeader() I want to refresh the page every 2 seconds. It works, but after 3 or 4 refreshes it hangs and I have to reset the whole board.

Of course with an embedded system I would use Ajax... here I thought reloading the page should be enough.

What might cause such a hang?
The code you have that says readString += c has to allocate a whole new string whenever it runs out of space for more characters. All those allocations are filling up memory. 

Instead of the String class, use a single C character array, e.g.

char s[128];

that is big enough for whatever you put in it.

If it helps, I wrote a simple arduino web server for my own project, and if you look at the code here that may give you ideas for how to implement this.