I read lot of articles about garbage collection and almost all article tells about heap memory. so my question is \"garbage collection collects stack memory or heap memory or bo
It collects heap memory. Usually, stack memory is collected automatically when the execution path reaches the end of the scope. e.g.:
void fun()
{
int n; // reservation on the stack as part of the activation record
...
} // returning the stack pointer to where it was before entering the scope
In fact, in a language like C++, stack allocated variables are called auto
variables.