Strings don't seem to be boosting the program size?

I'm at 96% memory usage, and I still have a lot that I want to add to the code. The code isn't close to being optimized fully, so there were several Strings that I could easily remove.

So, naturally, I went through my code, and removed each String/Serial print that I didn't need, expecting the code to use much less memory afterwards.

To my surprise, after doing that, I was still at 96%. What gives?

Sketch uses 1266090 bytes (96%) of program storage space. Maximum is 1310720 bytes.
Global variables use 58740 bytes (17%) of dynamic memory, leaving 268940 bytes for local variables. Maximum is 327680 bytes.

What gives?

What doesn't give is your code. The code you didn't post doesn't give us a clue.

If you are already preventing string literals from being copied to SRAM, by using the F() macro, then removing a string literal will not change the amount of SRAM being used.

PaulS:
What doesn't give is your code. The code you didn't post doesn't give us a clue.

If you are already preventing string literals from being copied to SRAM, by using the F() macro, then removing a string literal will not change the amount of SRAM being used.

It doesn't really matter what my actual code exactly says. Basically I'm just talking about a general case like this:

Before :

String output = "Gobballygook"; 
Serial.println(Gobballygook);

After:

//String output = "Gobballygook"; 
//Serial.println(Gobballygook);

I'm literally just completely removing Strings (which did not use the F() macro because they were simply there to test certain parts of the program) and the program size didn't change, which surprised me.

I'm writing this particular code for a company, and I signed a paper that probably doesn't matter. But that paper did say I can't give the code to other companies etc... Although I doubt you're here to steal my code, I think posting it online would still be a breach of my contract.

Although I doubt you're here to steal my code, I think posting it online would still be a breach of my contract.

You can write a simple sketch that illustrates the problem. If you can't, it is quite likely that the problem is not what you think it is.

PaulS:
You can write a simple sketch that illustrates the problem. If you can't, it is quite likely that the problem is not what you think it is.

I did. See above:

Before :

String output = "Gobballygook"; 
Serial.println(output);

After:

//String output = "Gobballygook"; 
//Serial.println(output);

Commented out half a dozen of these sorts of lines with no memory size changes.

I meant posting a real program that would actually compile.

String output = "Gobballygook";
Serial.println(Gobballygook);

You don't have anything to print called Gobballygook.

But, if you want to insist that commenting out code doesn't change the amount of SRAM or program memory being used, don't let my insistence on facts get in your way.

PaulS:
You don't have anything to print called Gobballygook.

lol man, fair catch, I should be more careful. Edited.

So you're saying it does change the amount of memory used, but that it's not a large enough change to account for 1% of the program space? I honestly believed Strings were worse for memory than they are I guess.

As requested, here is a code that will compile.

String Gobblygook = "Hello and thanks for reading, this sure should be wasting a lot of memory, right?";

void setup() {

}

void loop() {
  Serial.println (Gobblygook);

}

it uses this much space:

Sketch uses 205216 bytes (15%) of program storage space. Maximum is 1310720 bytes.
Global variables use 14484 bytes (4%) of dynamic memory, leaving 313196 bytes for local variables. Maximum is 327680 bytes.

Without any Gobblygook (comment out the String and the line printing it, or delete it entirely) and it uses this much space:

Sketch uses 205216 bytes (15%) of program storage space. Maximum is 1310720 bytes.
Global variables use 14484 bytes (4%) of dynamic memory, leaving 313196 bytes for local variables. Maximum is 327680 bytes.

I must be missing something, because the memory used should be changing here

I pasted your code into the IDE, and added a Serial.begin() call.

String Gobblygook = "Hello and thanks for reading, this sure should be wasting a lot of memory, right?";

void setup()
{
   Serial.begin(115200);
}

void loop()
{
  Serial.println (Gobblygook);
}

When I compile, for a Mega, I get:

Sketch uses 3148 bytes (1%) of program storage space. Maximum is 253952 bytes.
Global variables use 284 bytes (3%) of dynamic memory, leaving 7908 bytes for local variables. Maximum is 8192 bytes

When I comment out lines 1 and 10, and compile, I get:

Sketch uses 1712 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 182 bytes (2%) of dynamic memory, leaving 8010 bytes for local variables. Maximum is 8192 bytes.

I consider the 102 bytes of SRAM saved to be significant.

Clearly, you are not compiling the code you posted or you are compiling for something other than a Mega. I'm not sure where I got the idea that you were using a Mega. What ARE you compiling for? What ARE you compiling?

Okay, it turns out I'm not crazy after all, then. That is the result I expected to see. I am indeed compiling the same code, but you are right in saying it is not the Mega I am using.

I suppose what I'm using is probably the core of the confusion then. I honestly didn't believe I needed to talk about it because I thought the memory usage would decrease when you removed Strings universally, regardless of what kind of controller one happens to be using.

I'm not using an Arduino at all, I'm using an ESP32 wroom.

I'm using an ESP32 wroom.

That uses a completely different architecture compared to the AVR chips in most Arduinos.

I don't have that device, or any desire to clutter up my computer with unneeded cores, so I can't compile for your device.

PaulS:
That uses a completely different architecture compared to the AVR chips in most Arduinos.

I don't have that device, or any desire to clutter up my computer with unneeded cores, so I can't compile for your device.

Certainly, there is no need, I've been testing it for the last few minutes and I'm coming to the conclusion that the program size simply does not display correctly in the feed.

A completely empty code, for example, nets 15% memory usage, and a code with a few dozen lines still appears to use the same 15% memory. However, it's definitely not completely off base: My large code ( a few hundred lines) uses 96% as we talked about already, so it's generally in some sort of correct ballpark. Perhaps it just gives a general number, and doesn't adjust until large changes are made.

I'm going to try looking for another way to see how much memory you are actually using on the esp32, I will update if I find something.

Local automatic variables don't show up in the statistics, so deleting these does not help.
Unused code and functions are anyway deleted by the compiler during optimisation so deleting these will not help.
If the amount of flash memory is 1310720 bytes, to see a 1% change, you'd have to delete 13k of data.
Look for big arrays, big libraries including fonts for displays etc.

If I'm not mistaken, the static memory for String object is only 6 bytes. The actual memory for the characters are allocated dynamically on the heap. Not sure if the IDE reports heap memory either.

6v6gt:
Local automatic variables don't show up in the statistics, so deleting these does not help.
Unused code and functions are anyway deleted by the compiler during optimisation so deleting these will not help.
If the amount of flash memory is 1310720 bytes, to see a 1% change, you'd have to delete 13k of data.
Look for big arrays, big libraries including fonts for displays etc.

Alright, this is very helpful info, thanks!

@arduino_new - I'm not sure what you mean by "allocated dynamically on the heap"?