Array intefere with Display memory allocation

I recently found interesting issue, that display is not displaying properly, or even can't properly allocate the memory, because of existance of code related to arrays - getting array value with index converted out of string, to be precise.

I'm adding code with the way display is set:

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

and the part of code that added is causing the issue

    String number = "15";
    int newInterpolationData[][2] = {
      {1022, 1019}, {1017, 1014}, {1012, 1008}, {1005, 1000},
      {997, 994}, {990, 986}, {982, 971}, {956, 924},
      {907, 874}, {860, 824}, {813, 776}, {763, 726},
      {713, 678}, {665, 629}, {616, 578}, {565, 529},
      {509, 479}, {460, 430}, {411, 380}, {363, 332},
      {311, 282}, {264, 234}, {215, 184}, {167, 136},
      {119, 87}, {71, 43}, {43, 35}, {35, 28},
      {26, 20}, {18, 12}, {11, 7}
    };
    Serial.println(newInterpolationData[number.toInt()][0]);

I tested different configurations and display didn't allocate, or displaying was someting like offseted.

What can be the source of this issue? Changing "number.toInt()" to some fixed value solves the issue.

I can see that this can be same issue that was posted here:
https://forum.arduino.cc/t/weird-behavior-ssd1306-wont-work-if-an-array-is-declared/607689

Adafruit SSD1306 library? If so, it dynamically allocates 1kB of memory so you have to add 1kB to the reported dynamic memory usage.

So if the IDE reports 700 bytes memory dynamic usage you will have to add 1024 bytes. And with an 328P based board you will be at least in the danger zone.

Please post your full sketch and tell us which board you are using.

Using a fixed value will let the compiler substitute the number from the array into the code at compile-time. The compiler will then remove the entire array during optimization, because it is no longer needed.

Using the String data type will also cause problems, because the amount of dynamic memory (ram) used tends to increase over time as the String is created/destroyed in memory.

That means that repeated string allocation has fragmented free memory to no more memory available. String replacements of same length stay in place, are not reallocated.