ESP32 using more than 50.000 bytes of memory for WiFi

Hello, I tried to upgrade my old ESP32 S2 with a slightly modified sketch and surprisingly found out that it is now running out of memory. Is it possible that the latest libraries are using more memory than the old ones? I'm using arduino IDE 2.3.6 now.

I've written a simple test which shows that only WiFi itself is using more than 50.000 bytes. Unfortunately I've never tested it with earlier versions.

#include <WiFi.h>

void setup () {
                                            // TTGO T7 V1.3 Mini32              ESP32S2 Dev Module
                                            // ----------------------------------------------------
    size_t freeHeap1 = ESP.getFreeHeap ();  // 295.064                          152.800
                                            //
    Serial.begin (115200);                  //
                                            // 
    size_t freeHeap2 = ESP.getFreeHeap ();  // 292.680, Δ = 2.384               152.800, Δ = 0
                                            //
    WiFi.begin ("SSID", "password");        //
                                            //
    size_t freeHeap3 = ESP.getFreeHeap ();  // 242.504, Δ = 50.176 (17 %)       101.064, Δ = 51.736 (34 %)
                                            //
    while (WiFi.localIP ().toString () == "0.0.0.0") {
        delay (1000);                       //
        Serial.printf ("   .\n");           //
    }                                       //
    Serial.printf ("Got IP: %s\n\n\n", (char *) WiFi.localIP ().toString ().c_str ());
                                            //
    size_t freeHeap4 = ESP.getFreeHeap ();  // 241.576, Δ = 928                 99.916, Δ = 1.148
                                            //
    Serial.printf ("freeHeap1 = %u\n", freeHeap1);
    Serial.printf ("freeHeap2 = %u, Δ = %u\n", freeHeap2, freeHeap1 - freeHeap2);
    Serial.printf ("freeHeap3 = %u, Δ = %u\n", freeHeap3, freeHeap2 - freeHeap3);
    Serial.printf ("freeHeap4 = %u, Δ = %u\n", freeHeap4, freeHeap3 - freeHeap4);
}

void loop () {

}

I tested with pre-boards3, and the compile went from 62% to 49% of program space. Both are still quite large, though. I then changed to Huge App and that dropped it to 20%.
I then restored the board entry to the current 3.2.0 and the pgm space was 26%.

The version of the board's core platform would matter, not the IDE.

I've got an M5Stack CoreInk handy. With the esp32 board by Espressif, aka arduino-esp32, v3.0.7 (the current is 3.2.0?)

freeHeap1 = 311488
freeHeap2 = 309780, Δ = 1708
freeHeap3 = 264312, Δ = 45468
freeHeap4 = 263676, Δ = 636

The M5Stack board is based on the older v2 of arduino-esp32. I have 2.1.1 installed here

freeHeap1 = 308540
freeHeap2 = 311676, Δ = 4294964160
freeHeap3 = 265252, Δ = 46424
freeHeap4 = 264512, Δ = 740

Funny enough, some heap got freed after Serial.begin, but still about 45KB either way after starting to connect.

(BTW, String::c_str returns const char *, so the (char *) cast is unnecessary. Alternately, IPAddress is Printable, so

    Serial.print ("Got IP: "); Serial.println (WiFi.localIP ());

doesn't have quite as many newlines, but seems like less work.) Oh, now it says

freeHeap1 = 308540
freeHeap2 = 306692, Δ = 1848
freeHeap3 = 265260, Δ = 41432
freeHeap4 = 264512, Δ = 748

only 41KB. Hitting the reset button a dozen times, cannot reproduce; only getting the "negative" delta, 46KB one.

Are you directly checking the heap as in this sketch, or is there some other symptom?

And as for the size of the program, with v2

Sketch uses 710405 bytes (54%) of program storage space. Maximum is 1310720 bytes.
Global variables use 42428 bytes (12%) of dynamic memory

With v3

Sketch uses 897689 bytes (68%) of program storage space. Maximum is 1310720 bytes.
Global variables use 43712 bytes (13%) of dynamic memory

which is quite a bit larger.

so the chip has a radio. everything else for WiFi is a software linked to your sketch

No, I'm usually not checking the heap as long as everything works fine. But now my sketch doesn't work any more so I was looking for a reason for this. It seems that the WiFi library has grown a little lately and I will have to optimize my code so that it will use less memory itself.

Thank you all for your answers.