Garbage collector (Garbage collectors)

Source: Internet
Author: User

  • What is the purpose of garbage collection in Java? When does garbage collection take place?
    • The purpose of garbage collection is to identify and discard objects that the app is no longer using to free and reuse resources.
  • What will System.GC () and RUNTIME.GC () do?
    • These two methods are used to prompt the JVM for garbage collection. However, starting or delaying a garbage collection immediately depends on the JVM.
  • When is the Finalize () method called? What is the purpose of the destructor (finalization)?
    • The garbage collector calls the object's Finalize () method before releasing the memory occupied by the object. It is generally recommended that the resources held by the object be disposed of in this method.
  • If the object's reference is set to NULL, will the garbage collector immediately release the memory occupied by the object?
    • No, in the next garbage collection cycle, this object will be recoverable.
  • What is the structure of the Java heap like? What is the permanent generation in the heap (Perm Gen space)?
    • The JVM's heap is the run-time data area, and all instances and arrays of classes are allocated memory on the heap. It is created when the JVM is started. The heap memory that the object occupies is reclaimed by the automatic memory management system, which is the garbage collector.
    • Heap memory is made up of surviving and dying objects. The surviving objects are accessible to the app and are not garbage collected. The object of death is the object that the app is inaccessible and has not been reclaimed by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.
  • What is the difference between a serial (serial) collector and a throughput (throughput) collector?
    • The throughput collector uses a parallel version of the new generation garbage collector, which is used for medium-sized and large-scale data applications. The serial collector is sufficient for most small applications, which require about 100M of memory on modern processors.
  • In Java, when can objects be garbage collected?
    • This object can be recycled when the object becomes inaccessible to applications that currently use the object.
  • Will garbage collection occur in the JVM's permanent generation?
    • Garbage collection does not occur in a permanent generation, and if it is permanently full or exceeds the threshold, a full GC is triggered. If you look closely at the output of the garbage collector, you will find that the permanent generation is also recycled. This is why the correct permanent generation size is very important for avoiding full GC. Please refer to the following Java8: from the permanent generation to the Meta data area
    • (Translator Note: The JAVA8 has removed the permanent generation, adding a new native memory area called the metadata area)

Garbage collector (Garbage collectors)

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.