Author: huaqing visionary lecturer
Memory overflow (out of memory): When memory space is low and more memory space is needed, it can overflow memory, such as loading large pictures into memory, which usually results in memory overflow. Stack full time to do into the stack must produce space overflow, called overflow, stack empty when the stack also produces space overflow, called underflow. Is that the allocated memory is not enough to drop the sequence of data items, called a memory overflow.
Memory leaks (memory leak): Existing objects, when no longer in use, can not release the space that has been requested, one or more memory leaks can be ignored, but multiple memory leakage accumulation will cause memory space consumption, resulting in memory overflow, you apply to the system to allocate memory for use (new) , but does not return after the use of (delete), the result you apply to the block of memory you can no longer access (perhaps you have lost its address), and the system can not assign it to the required program. This is overflow!
In the manner in which they occur, memory leaks can be categorized into 4 categories:
1. Frequent memory leaks. The code that has a memory leak is executed multiple times, causing a memory leak each time it is executed.
2. Accidental memory leaks. The code that occurs with a memory leak only occurs under certain circumstances or procedures. The frequent and incidental are relative. For a given environment, the occasional may become a frequent occurrence. So test environments and test methods are critical to detecting memory leaks.
3. Disposable memory leak. The code that has a memory leak is executed only once, or because of an algorithm flaw, there will always be a single and one memory leak. For example, allocating memory in the constructor of a class does not release that memory in the destructor, so a memory leak occurs only once.
4. An implicit memory leak. The program keeps allocating memory while it is running, but it does not release memory until the end. Strictly speaking, there is no memory leak, because the final program frees up all of the requested memory. But for a server program, it can take days, weeks, or months to run out of memory, which may result in the eventual exhaustion of all of the system's memory. So, we call this kind of memory leak as an implicit memory leak.
The general implicit memory leak is not easy to detect, because from creation to release, it seems that there is no fault, but the long-running operation will also lead to leaks, we can check the memory through two functions in Ddms: heap view heap distribution; allocation Tracker tracks memory allocations.