The characteristics of Java garbage collection mechanism

Source: Internet
Author: User

on the characteristics of Java garbage collection mechanism:

1. The goal of the garbage collection mechanism is to reclaim the memory space of useless objects (remember: not objects), which is the memory space of the JVM heap memory. Garbage collection only reclaims memory resources, for those physical resources, such as database connection, SOCKET,I/O stream and other resources incompetent, we have to shut down the recovery.

2. In order to speed up the garbage collection mechanism to reclaim the memory space occupied by those useless objects, we can say that the reference variable of the object is placed in null (remember: the garbage collection mechanism does not execute immediately when NULL is placed).

3. Potential drawbacks of the garbage collection mechanism its overhead can affect performance. The Java virtual machine must keep track of the objects that are useful in the program to determine which objects are useless and free up memory space for those useless objects. This process takes the processor time.

4. The unpredictability of garbage collection. We can recommend that the system be garbage collected through the GC () method of the runtime object or System.GC (), but we cannot precisely control the garbage collection mechanism's operation.

Summary: When writing a program, one of the basic principles is: do not refer to objects that are no longer needed. If you keep a reference to them, the garbage collection mechanism temporarily does not reclaim the memory they occupy, the system has less memory available, and when the system has less available memory, the garbage collection mechanism executes more frequently, resulting in degraded system performance.

The characteristics of Java garbage collection mechanism

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.