Differences between memory overflow and Memory leakage

Source: Internet
Author: User

Differences between memory overflow and Memory leakage

Memory overflow out of memory means that the program does not have enough memory space to use when applying for memory. For example, if an integer is applied, however, if a long value is saved to it, the memory overflow occurs.

Memory leakage memory leak refers to the failure of the program to release the applied memory space after applying for memory. The memory leakage hazard can be ignored once, but the memory leakage accumulation result is very serious, no matter how much memory, sooner or later.

Memory leak will eventually cause out of memory!

Memory overflow means that the amount of memory you need to allocate exceeds what the system can offer. If the system cannot meet your needs, it will cause an overflow.

Memory leakage means that you apply to the system to allocate memory for use (new), but do not return it after use (delete ), as a result, the memory you applied for cannot be accessed by yourself (maybe you have lost its address), and the system cannot allocate it to the required program again. A plate can only contain four fruits in a variety of ways. If you have five fruits, you cannot eat them if you drop them. This is overflow! For example, stack overflow occurs when the stack is full. Stack Overflow also occurs when the stack is empty. That is, the allocated memory is insufficient to put down the data sequence, which is called memory overflow.

Memory leakage can be classified as follows:

1. Frequent Memory leakage. Code with Memory leakage will be executed multiple times, resulting in a memory leak each time it is executed.
2. Occasional Memory leakage. Memory leakage occurs only in certain environments or operations. The frequency and frequency are relative. For a specific environment, unexpected events may become frequent. Therefore, the test environment and test method are crucial for detecting memory leaks.
3. One-time memory leakage. The code with Memory leakage is executed only once, or due to algorithm defects, there will always be only one piece of Memory leakage. For example, if the class constructor allocates memory but does not release the memory in the destructor, the memory leakage only occurs once.
4. Implicit Memory leakage. The program continuously allocates memory during the running process, but it does not release the memory until it ends. Strictly speaking, there is no memory leakage because the program releases all requested memory. However, if a server program needs to run for several days, weeks, or even months, failing to release the memory in time may eventually exhaust all the system memory. Therefore, we call this type of Memory leakage an implicit memory leak.

From the perspective of user programs, memory leakage does not cause any harm. As a general user, the memory leakage does not exist. The real danger is the accumulation of Memory leakage, which will eventually consume all the memory of the system. From this perspective, one-time memory leakage is not harmful because it will not accumulate, while implicit memory leakage is very harmful because it is more difficult to detect than frequent and occasional memory leaks.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.