Java: Memory leaks and memory overflows

Source: Internet
Author: User

1. memory Overflow (Overflow)

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.

2. memory Leak (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.

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

(1) Common memory leaks: code that occurs with a memory leak is executed multiple times, causing a memory leak each time it is executed.

(2) Sporadic memory leaks: code that occurs with a memory leak can occur 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) A one-time memory leak: The memory leak code will only be executed once, or due to the shortcomings of the algorithm, there will always be a piece of memory only and a leak. 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) Implicit memory leak: The program allocates memory while it is running, but 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.

Summarize:

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 of the system's memory, resulting in a final memory overflow . 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.

Java: Memory leaks and memory overflows

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.