Stack is used for static memory allocation and Heap for dynamic memory allocation, both stored in the computer's RAM . ... Variables allocated on the heap have their memory allocated at run time and accessing this memory is a bit slower, but the heap size is only limited by the size of virtual memory .