The stack is an area in memory that is reserved for your program. It's typically pretty small, relative to your total memory.
Uk Marine wrote: |
---|
Stack overflow happens when all the memory in the stack has been allocated |
Uk Marine wrote: |
---|
And [a stackoverflow] happens when the computer no longer has any memory left |
These two statements are not equal. At all.
Outside source:
Wikipedia wrote: |
---|
In software, a stack overflow occurs when the stack pointer exceeds the stack bound. ... When a program attempts to use more space than is available on the call stack (that is, when it attempts to access memory beyond the call stack's bounds, which is essentially a buffer overflow), the stack is said to overflow. |
Uk Marine wrote: |
---|
so it's best to allocate on the heap and then free the memory later on as i've said. |
Again, false. It's only best to use the heap if the stack does not work for your purpose. There are many situations where the stack is not suitable, but this does not mean you should blindly use the heap. Allocating memory on the heap is an expensive operation, which can be very error prone.
So, OP, it is best to use the stack unless you actually
have to use the heap.
Again,
Uk Marine, it is fine to be ignorant of topics. Nobody knows everything. But don't act like you know what you are talking about when you don't. It does nothing but spread false information, confuse newbies, and give us all a bad image.
More sources for OP:
Performance on stack vs heap:
http://stackoverflow.com/a/161061/2887128
Why you should minimize heap usage:
http://stackoverflow.com/q/6500313/2887128
Wikipedia article about memory leaks:
http://en.wikipedia.org/wiki/Memory_leak