ATmega328P / NANO.. Any tips on memory usage pitfals?

I've experimented and gathered the electronic resources I need for what will be my largest product to date. So its a good time to pick everyone's brains about the pitfals of coding, especially when it comes to memory usage. I understand things like using 8 bit vars when 16 or 32 bits isn't necessary, but what about general things we take for granted in C/C++ coding. For example...

  • in larger systems, variables passed to a function/method are put on the stack, as are non static variables declared within the scope of the function. So in that case, all memory used is recovered after returning from the function. Is that true while the Arduino compiler?
  • If I create variables, structures, or arrays using the C++ 'new' keyword, is that memory recovered when I delete? What about the older 'malloc()' and 'free()' collection of calls?
  • I see a lot of example code where vited RAM memory, is there any kind of "report" tool or info file createariables are re-used fmy or purposes that make their names less than informative. If variables are being re-used, or even 'over worked' like this, does this mean variables don't really 'go away'?
  • If (as i suspect) it is easy to run out of certain kinds of limd by my builds, to I can check on my resource usage as project is developed?

Thanks for any pointers. Yes I KNOW I can google this subject, but what I'm looking for is the kind of hidden "gotchas" as well as often undocumented "work arounds" that people have found.

PeterPan321:
Is that true while the Arduino compiler?

Yes.

PeterPan321:
If I create variables, structures, or arrays using the C++ 'new' keyword, is that memory recovered when I delete? What about the older 'malloc()' and 'free()' collection of calls?

From a memory management perspective new/delete and malloc/free have the same semantics.

The answer is "maybe". The key phrase is "heap fragmentation"...

https://www.google.com/search?q=heap+fragmentation

PeterPan321:
I see a lot of example code where vited...

I don't understand what you are asking.

PeterPan321:
If (as i suspect) it is easy to run out of certain kinds of limd by my builds...

Ditto.

PeterPan321:
Thanks for any pointers.

F-macro.

const.

Arduino flash library.

Fatter more complex classes (to reduce the number of VMT tables).

Leaner more simple classes (to reduce the amount of unused reserved memory).

Get it working before optimizing. Always.

Choose the correct algorithms early.