In a memory layout of a program, what happens when the stack and the heap both grow and hit each other?
I am learning about C++ and the memory layout. I was taught that when a program is loaded into memory, a block of memory will be given to the program by the operating system. This block can be divided into 3 regions: static, stack and heap. The size of both the stack and the heap can grow or shrink during the lifetime of a program within this block of memory, and grows towards the direction of each other. So what happens next if there are no unallocated space left and the stack and the heap hit each other? High addresses
\+-------------+
| Stack |
\+-------------+
| Unallocated |
| Space |
\+--------------+
| Heap |
\+--------------+
Low addresses
Additional question: I am aware that you must manually free memory when you no longer use it to avoid memory leaks. But what does "memory" in "memory leaks" refer to? The heap memory in a program or the actual memory itself? #dev #technology #programming