Variable scope and RAM [solved]

When a variable goes out of scope is that RAM memory released/freed?

void setup() {
  int x = 69;  //using ram memory
}
void loop() {
  //is the ram that stored 69 released/freed?
}

Yes, because C locals live on the stack.

Once the procedure defining a local variable returns, the location on the stack reserved for that local is released with the rest of the stack frame to become free stack space (or more properly free space between the stack and the malloc heap).

-br

Thanks billroy

This is an interesting idea. Where could I read more about how it is implemented in an Arduino?

...R

billroy:
Once the procedure defining a local variable returns, the location on the stack reserved for that local is released with the rest of the stack frame

https://www.google.com/search?q=avr+gcc+stack+frame
https://www.google.com/search?q=avr+gcc+register+allocation
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_reg_usage

Thanks, I'll study those links.

...R