I understand the fact that stack grows upwards and heap grows downwards or vice-versa (architecture dependent). But, i couldn't find much details about how actually it's implemented, my doubt is, for every process a memory block will be allocated, but is there a restriction on, how much max chunk can be used for stack or heap? Or are there no restrictions till whole allocated memory is consumed?
1 Answer
Yes, processes have predetermined stack sizes. Have you ever tried to recurse a method/function too much? You get a StackOverflow exception. That doesn't mean you've already went through your entire computer's memory. The OS controls distribution of stack and heap memory for each process.
1 Comment
instance
That doesn't mean you've already went through your entire computer's memory -- I agree, but definitely memory chunk allocated for that process is exhausted. I belive StackOverflow occurs only when you have no more memory for that process only (not whole memory of system).