← Back to list

Does comments count as memory inside Arduino?

No, comments do NOT count as memory usage inside an Arduino. Let me explain this in detail:

Ampheo · 2025-09-26 07:30 · 0 claps · 2.0 min read
#arduino #comment #memories #eeprom #arduino-uno
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT

Does comments count as memory inside Arduino?

No, comments do NOT count as memory usage inside an Arduino. Let me explain this in detail:

What Happens to Comments

Comments are completely ignored by the compiler during the compilation process. Here’s what happens:

  1. Preprocessing Stage: Before actual compilation, the preprocessor removes all comments from your code
  2. Compilation: The compiler only sees the actual code statements, functions, and variable declarations
  3. Memory Usage: Only the compiled machine code and data allocations affect memory usage

Memory Types in Arduino

When we talk about “memory” in Arduino, we typically mean:

1. Flash Memory (Program Memory)

  • Stores your compiled program code
  • Comments have ZERO impact on flash memory
  • Only your actual code instructions are stored here
  • Example: ATmega328P (Arduino Uno) has 32KB of flash

2. SRAM (Runtime Memory)

  • Used for variables during program execution
  • Comments have ZERO impact on SRAM
  • Only variables, arrays, and dynamic allocations use SRAM
  • Example: ATmega328P has only 2KB of SRAM

3. EEPROM

  • Non-volatile memory for storing data between power cycles
  • Comments have ZERO impact on EEPROM

Practical Example

cpp

// This is a comment - it uses NO memory
// This comment explains the variable below
int sensorValue = 0;  // This variable uses 2 bytes of SRAM

/*
 * This multi-line comment
 * uses absolutely NO memory
 * at all in the Arduino
 */

void setup() {
  // Comment: initialization code
  Serial.begin(9600);  // This function call gets compiled and uses flash memory
}
void loop() {
  // This comment disappears during compilation
  sensorValue = analogRead(A0);  // This code uses flash memory
}

How to Check Actual Memory Usage

In Arduino IDE:

  • After uploading, check the console output:

text

Sketch uses 1234 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 45 bytes (2%) of dynamic memory, leaving 2035 bytes for local variables.

These numbers reflect ONLY your actual code, NOT comments.

Best Practices Regarding Comments

  1. Comment Liberally: Don’t worry about memory — comments make code maintainable
  2. Use Descriptive Comments: They help you and others understand the code later
  3. Remove Debug Comments: Only if you’re hitting memory limits and need to reduce code size

When Comments Might “Indirectly” Affect Memory

The ONLY scenario where comments could indirectly relate to memory is:

  • If you’re using version control (like Git), comments increase the size of your source code repository
  • But this has nothing to do with the Arduino’s actual memory usage

Conclusion

Comments are completely free in terms of Arduino memory usage. They are stripped out before your code even gets to the microcontroller. Feel free to comment your code extensively — it’s a good programming practice that costs you nothing in terms of microcontroller resources.

The memory usage you see reported in the Arduino IDE reflects only your actual code and variables, never your comments.


메타데이터
post_id
313e6048ba87
slug
does-comments-count-as-memory-inside-arduino-313e6048ba87
url
https://medium.com/@pqshedy33/does-comments-count-as-memory-inside-arduino-313e6048ba87
canonical_url
https://medium.com/@pqshedy33/does-comments-count-as-memory-inside-arduino-313e6048ba87
author_url
https://medium.com/@pqshedy33
status
ok
fetched_at
2026-07-17 06:58:23