Memory overflow and memory leaks

Source: Internet
Author: User

Memory overflow means that the system does not give enough memory for its use, out of memory, when the program is requesting it.

Memory leaks are self-application to the system memory space but not released after use, the result that block of memory can not be used, the system can not be assigned to other programs to use again.

A memory leak can be ignored, but multiple memory leaks will eventually cause memory overflow.

Memory leaks can be divided into 4 types:

1. A common memory leak, a memory leak code will be accessed multiple times, each time it is executed will cause a memory leak.

2. Accidental memory leaks. Code that occurs with a memory leak occurs only under certain circumstances or during operation. The occurrence and the incidental sex are opposite. For a given environment, the occasional may become a common occurrence. Therefore, test environments and test environments are critical to detecting memory leaks.

3. Disposable memory leaks. The code that occurs with a memory leak is only executed once, or because of an algorithmic flaw, there is always a piece of memory that leaks. For example, allocating memory in a class's constructor does not release the kernel 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 the requested memory. But for a server program that needs to run for days, weeks, or months, not releasing memory in time can also 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.

Memory out-of-bounds refers to a program requesting a memory, but in the process of running the actual space is larger than the size of the requested memory.

Buffer overflow:

A buffer overflow is when the computer fills the buffer with data bits that exceed the buffer memory's capacity overflow data overwrite the legitimate data, ideally when the program checks the length of the data does not allow the input of characters that exceed the buffer length, but most programs assume that the data length always matches the allocated memory space. This is the hidden danger for buffer overflow, the buffer used by the operating system, also known as the "stack". Between the various operators, the instruction is temporarily stored in the stack, and the stack also has a buffer overflow.

Stack Overflow:

A stack overflow is a buffer overflow. The use of buffer overflows to make useful storage units rewritten can often lead to unpredictable consequences. In the process of running the program, in order to temporarily access the data needs, generally allocate some memory space, usually these spaces are buffers. If you write data to a buffer that is longer than its own length, so that the buffer cannot hold, it causes the storage unit outside the buffer to be overwritten, a phenomenon known as a buffer overflow

A stack overflow is a buffer overflow.

Memory overflow and memory leaks

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.