* Heap overflow : ceaseless new An object , Always create new objects ,
* Stack overflow ： Dead loop or recursion is too deep , The reason for recursion , It may be too big , It may not end .
* In a function call , The stack will be pressed in order ： parameter , Return address ,EBP. If the function has local variables , next , The corresponding space is opened in the stack to construct variables .
* Examples are as follows ：
So what is the stack ? If the computer is a white-collar , So the stack is his desk . In order to complete the boss （ program ） Work to account for , This white-collar needs to take out data from the bookshelf or cabinet to check and process . The so-called stack overflow is to solve a task , There's too much information or too much temporary data to process, and the table is full , Then the white-collar went on strike ....
But generally , This desk is big enough , So stack overflow is usually the boss （ program ） There was a problem with the work of the account . The most common is infinite recursion , For example, to solve problems A, The problem must be solved first B, To solve the problem B, The problem has to be solved A, At this time, this white-collar keeps writing notes to solve the problem A, When you're halfway through, you have to take notes to solve the problem B, I still have to write notes to solve the problem A, So repeatedly , Soon the table was filled with notes （ Overflow ）.
* usually 「 stack overflow 」 It means 「 call Stack （call
stack） Overflow of 」. It can be difficult to interpret the call stack in a popular way , Because it involves a lot of other computer architecture knowledge . The answer is simply to explain the characteristics of the stack data structure ── First in, second out ／ Last in, first out . Overflow refers to the overflow of this data structure , Can't store more data . Other data structures also encounter this situation . Even if the data structure is not fixed capacity , It's scalable , In the limited memory space, there is still a chance of overflow .
in addition , A lot of times ,「 Call stack overflow 」 The emergence of is and recursion （recursion） dependent . We can change some recursive implementations to iterations （iteration）, But sometimes you have to have a custom stack data structure , For example, depth first search of trees （Depth-First
Search, DFS）. The custom stack may overflow .
therefore , Although a stack overflow is often referred to as a call stack overflow , But in essence, it is just a kind of overflow of data structure .