When we use C + + as the underlying driver, we often encounter a warning of insufficient memory, the reason is often because of memory overflow, leakage or cross-border and other reasons. So what's the connection between them? memory overflow (out of memory)
Refers to a program that does not have enough memory space to use when requesting memory. memory leaks (memory leak)
Is that the program is unable to release the requested memory space after the application has been applied for memory, consuming useful memory. Note: Memory leaks will eventually result in memory overflow
Simply understood, a memory overflow is required to allocate more memory than the system gives. A memory leak points to system request allocation memory for use (new), but does not return (delete) when it is exhausted, resulting in active memory consumption.
Memory leaks can be grouped into 4 categories:
1. Frequent memory leaks
The code that causes the memory leak will be executed many times and will cause a memory leak every time it is executed
2. Accidental memory leaks
A memory leak can be caused by executing code that causes a memory leak in certain environments
The importance of test environments and test methods in the lifecycle of the program is essential in terms of both of these memory leaks.
3. Disposable Memory leak
The code executes only once, but there is always a chunk of memory leaking, and the destructor does not release memory when it is more common in the constructor class.
4. Implicit leakage
While the program is running continuously allocating memory until the end of the release of memory, but the general server program will run for a long time, not released in time will also lead to memory exhaustion so that memory leaks.
To sum up, a one-time memory leak on the user's program maintenance is nothing substantial harm, but in real life, we still try to avoid this kind of event occurs. memory out of bounds refers to the system to request a piece of memory, when used but exceeded the scope of the application. For example, some functions to manipulate memory: sprintf, strcpy, strcat, vsprintf, memcpy, Memset, Memmove. When the code that caused the memory leak runs, the error is unavoidable and usually results in 1. Destroys memory memory allocation information in the heap 2. Destroys the memory space of other objects in the program 3. Free memory block attached: If before your program runs everything normal, However, because you have added several classes of member variables or modified a portion of the code (if you make sure that your modifications are correct) and cause the program to be wrong, consider whether the memory is corrupted and focus on whether the memory is out of bounds. buffer Overflow (stack overflow) programs typically allocate some memory space, called buffers, for temporary access to data. If you write data to a buffer that cannot be accommodated, the opportunity causes a storage cell other than the buffer to be overwritten, known as a buffer overflow. and the stack overflow is a buffer overflow, the principle is the same. Divided into upper overflow and down overflow. Among them, the overflow refers to the stack full and add new data to it, resulting in data overflow, the next overflow refers to the empty stack and delete operations, resulting in space overflow.