ESP 8266 memory

Good evening.
I am writing from Italy.
I would ask you some questions.
I am using Arduino's IDE to compile a simple code for the integrated wifi on the ESP.

The problem is that, after several iterations, memory drops down (is that the exact verb?)

I show you a memory-time graphic.

Code is very simple.

#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}

const char* ssid     = "FASTWEB-1-2EED7F";
const char* password = "B9AF909FEE";
const char* url = "http://www.*.it/*/classes.php";

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
 
void setup() {
 
  Serial.begin(115200);                                  //Serial connection
  WiFi.begin(ssid, password);   //WiFi connection
 
  while (WiFi.status() != WL_CONNECTED) {  //Wait for the WiFI connection completion
 
    delay(500);
    //Serial.println("Waiting for connection");
 
  }
 
 
}
 
void loop() {
 
 if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
  
   HTTPClient http;    //Declare object of class HTTPClient
   String url_ESP_on = url;
   url_ESP_on += "?request=showUsingMacAddress&version=ESP1.0&MacAddress=";
   url_ESP_on += WiFi.macAddress();
   //Serial.println("Sto contattando l'indirizzo " + url_ESP_on);
   http.begin(url_ESP_on);      //Specify request destination
   http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 
   int httpCode = http.POST("");   //Send the request
   String payload = http.getString();                  //Get the response payload
 
   //Serial.println(httpCode);   //Print HTTP return code
   //Serial.println(payload);    //Print request response payload
 
   http.end();  //Close connection
   
   String url_request = url;
   url_request += "?request=cleanAllUsingMacAddress&MacAddress=";
   url_request += WiFi.macAddress();
   //Serial.println("Sto cancellando l'ultimo comando contattando l'indirizzo " + url_request);
   http.begin(url_request);      //Specify request destination
   http.addHeader("Content-Type", "application/x-www-form-urlencoded");
 
   httpCode = http.POST("");   //Send the request
   payload = http.getString();                  //Get the response payload
 
   //Serial.println(httpCode);   //Print HTTP return code
   //Serial.println(payload);    //Print request response payload
 
   http.end();  //Close connection

    //Serial.print("freeMemory()=");
    Serial.println(system_get_free_heap_size());
   url_ESP_on = "";
   url_request = "";
 
 }else{
 
    Serial.println("Error in WiFi connection");   
 
 }
 
  delay(500);  //Send a request every 30 seconds
 
}

Do you have any suggestion?

This esp is supposed to work 24/7 for years.

Thank you very much

Try to get rid of String object, use a char buffer instead, it should help.

Ciao, Ale.

I think somehow payload isn't getting freed... couldn't say why though.