Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between memory leak and memory overflow

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

The editor will share with you the difference between memory leak and memory overflow. I hope you will gain a lot after reading this article. Let's discuss it together.

Difference: memory overflow means that when the program applies for memory, there is not enough memory space for its use, and the system can no longer allocate the space you need; memory leak means that the program cannot release the applied memory space after applying for memory. The harm of a memory leak can be ignored, but more memory leaks will lead to memory overflow.

Memory overflow (out of memory) means that when a program applies for memory, it does not have enough memory space for its use. When out of memory; appears, such as applying for an integer, but saving long to it, it can save the number, that is, memory overflow.

Memory leak (memory leak) means that the program cannot release the applied memory space after applying for memory. The harm of a memory leak can be ignored, but the consequence of memory leak accumulation is very serious. No matter how much memory it is, it will be occupied sooner or later.

Memory leak will eventually lead to out of memory!

Memory overflow means that you ask for more memory than the system can give you, and the system cannot meet the demand, so there is an overflow.

Memory leak means that you apply to the system for allocating memory for use (new), but do not return it after use (delete). As a result, you can no longer access the piece of memory you applied for (maybe you lost its address), and the system cannot allocate it to the needed program again. A plate can only hold four fruits in various ways, but you have five, and you fall to the ground and can't eat it. This is spillover! For example, the stack, when the stack is full, it is bound to produce space overflow, which is called upper overflow, and when the stack is empty, it also produces space overflow, which is called underflow. That is, the allocated memory is not enough to put down the sequence of data items, which is called memory overflow.

Classified by the way they occur, memory leaks can be divided into four categories:

1. Frequent memory leaks. Code that has a memory leak is executed multiple times, resulting in a memory leak each time it is executed.

2. Occasional memory leak. Code that has a memory leak occurs only in certain environments or operations. Recurrent and sporadic are relative. For a particular environment, sporadic may become frequent. Therefore, the test environment and test methods are very important to detect memory leaks.

3. One-time memory leak. The code that has a memory leak will only be executed once, or because of an algorithmic flaw, there will always be a leak of only one piece of memory. For example, memory is allocated in the constructor of a class, but not freed in the destructor, so a memory leak occurs only once.

4. Implicit memory leak. The program keeps allocating memory while it is running, but it doesn't release memory until the end. Strictly speaking, there was no memory leak here, because in the end, the program freed all the requested memory. But for a server program, it takes days, weeks, or even months to run, and not releasing memory in time can eventually deplete all the memory in the system. Therefore, we call this type of memory leak an implicit memory leak.

From the point of view of the user using the program, the memory leak itself will not cause any harm, as the general user, can not feel the existence of the memory leak at all. What is really harmful is the accumulation of memory leaks, which will eventually consume all the memory of the system. From this point of view, one-time memory leaks are harmless because they do not accumulate, while implicit memory leaks are very harmful because they are more difficult to detect than recurrent and sporadic memory leaks.

After reading this article, I believe you have some understanding of the difference between memory leak and memory overflow. If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report