Hello eran yasso,
Global variables (and also static variables) occupy a fixed, linker determined location in RAM. The number of global variables should have no bearing on stack size requirements.
The stack is used for temporary storage of data, such as -
- Return address data for each function call.
- Register values and return address data during an interrupt.
- Function parameter data.
- Local variables within a function.
- Additional temporary variables required by library functions and operations, e.g. arithmetic operations.
The last item is quite significant if you are using floating point arithmetic, and even more so if you are using trigonometric or other complex library functions.
Yes, the stack space is eventually released. The required stack size will depend of the degree of function nesting, in conjunction with the factors listed above.
Regards,
Mac