Java in System.GC () and Runtime.getruntime (). GC ()

Source: Internet
Author: User

(1) GC is garbage collection meaning (Gabage Collection), memory processing is the programmer is prone to problems, forget or wrong memory recycling will cause the program or system instability or even crash, The GC functionality provided by Java can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory.

(2) for GC, when a programmer creates an object, the GC starts to monitor the object's address, size, and usage. Typically, a GC uses a graph to record and manage all objects in the heap. In this way, you determine which objects are "accessible" and which objects are "unreachable." When the GC determines that some objects are unreachable, it is the responsibility of the GC to reclaim those memory spaces. OK. The programmer can manually execute System.GC () to notify the GC to run, but the Java language specification does not guarantee that the GC will execute.

(3) Garbage collection is a dynamic storage management technology that automatically frees objects that are no longer referenced by the program and, when an object is no longer referenced, implements the ability to automatically recycle resources according to a specific garbage collection algorithm.

(4) System.GC (); The garbage collector that calls the Java Virtual machine runs garbage that reclaims the memory.

(5) When there is no reference to an object, we assume that the object is no longer needed, the storage unit that the object occupies can be retracted and can be reclaimed by the System.GC () method, but it is generally better to label the object that is no longer referenced as null.

(6) Each Java application has a runtime class instance that enables the application to connect to the environment in which it is running. The current runtime can be obtained through the GetRuntime method. Runtime.getruntime (). GC ();

(7) Java.lang.System.gc () is just a shorthand for java.lang.Runtime.getRuntime (). GC (), the behavior of the two is no different.

(8) The only difference is that System.GC () writes more than Runtime.getruntime (). GC () Simple point. There is basically no chance of getting this command, because this command only advises the JVM to schedule the GC to run, and it may be completely rejected. The GC itself is automatically run periodically, the JVM decides to run the time, and now the version has a variety of more intelligent mode can choose, but also according to the running machine automatically choose, even if there is a performance demand, should also go to the GC operation mechanism to fine-tune, Instead of using this command to achieve performance optimizations.

Java in System.GC () and Runtime.getruntime (). GC ()

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.