Java Cluster optimization-must-know memory overflow and memory leaks

Source: Internet
Author: User

Concept:

Memory overflow out of

Refers to the program in the application of memory, there is not enough memory space for its use, an out of the memory, such as the application of an integer, but to save it a long to save the number, that is, Ram overflow.

Memory Leak Memories leak

Refers to the program after the application of memory, unable to free the requested memory space, a memory leak hazard can be ignored, but the memory leak accumulation of serious consequences, no matter how much memory, sooner or later will be occupied.

Contact:

Memory leak will eventually lead out of the memory, which is what you asked to allocate more than the system can give you, the system can not meet the demand, so overflow.

Let's look at this picture to understand the following:





Detailed

A memory leak is when you request a system to allocate memory for use (new), but you don't return it after you've used it (delete), and you can't access the memory you're applying to (maybe you lost the address), and the system can't assign it to the required program again. A plate with all kinds of methods can only Pack 4 fruit, you installed 5, the result fell on the ground can not eat. This is overflow! such as the stack, the stack when the stack is bound to create a space overflow, called overflow, stack empty and then do the fallback stack also produces a space overflow, called underflow. Is that the allocated memory is not enough to drop the sequence of data items called a memory overflow.

Classification:

In the way that happens, memory leaks can be categorized into 4 categories:

1. Frequent memory leaks. The code that occurs in memory leaks is executed multiple times, causing a memory leak each time it is executed.
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 frequent occurrence. So test environments and test methods 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 the class's constructor does not release the 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 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.


Harm:

From the user's point of view of using the program, the memory leak itself does not have any harm, as a general user, there is no sense of memory leaks. What is really harmful is the accumulation of memory leaks, which eventually consumes all the memory of the system. From this point of view, a one-time memory leak is harmless, because it does not accumulate, and the implicit memory leak is very harmful because it is more difficult to detect than the usual and sporadic memory leaks


Summarize:

We operate certain variables, the IDE provides us with a very good convenience, the JVM encapsulates a good automatic garbage collection mechanism for us, but we still that sentence, people are unreliable, this sentence makes us know ourselves repeatedly, the same, memory problems, we also need to delve into, Because this is the inevitable place for large-scale software optimization!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Cluster optimization-must-know memory overflow and 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.