11th questions (garbage collection), garbage collection

Source: Internet
Author: User

11th questions (garbage collection), garbage collection

1. Runtime class

Each Java application hasRuntimeClass instance, so that the application can be connected to the running environment. You can usegetRuntimeMethod to obtain the current runtime.

Applications cannot create their own Runtime instances.

public static Runtime getRuntime()
Returns the runtime objects related to the current Java application. RuntimeMost methods of the class are instance methods and must be called based on the current runtime object.

Return Value:
Related to the current Java application RuntimeObject.

public long freeMemory()
Returns the amount of free memory in the Java Virtual Machine. Call gcMethod may cause freeMemoryThe returned value is increased.
Return Value:
The approximate total amount of memory available for future object allocation, in bytes.
(A error)

public void gc()
Run the garbage collector. Calling this method means that the Java Virtual Machine has made some efforts to recycle unused objects, so that the memory occupied by these objects can be reused quickly. When the control is returned from the method call, the virtual machine has done its best to recycle all discarded objects.

NamegcIndicates the "Garbage Collector ". The virtual machine automatically executes the Recycle Process in a separate thread as needed, or even explicitly callsgcMethod.

Method System. gc () is a traditional and convenient method to call this method.

Gc is a non-static method,

Therefore, Runtime. getRuntime (). gc ();

B Error

Ii. System class

public static void gc()
Run the garbage collector.

CallgcThe method implies that the Java Virtual Machine has made some efforts to recycle unused objects so that they can quickly reuse the memory currently occupied by these objects. When the control is returned from the method call, the virtual machine has done its best to reclaim space from all discarded objects.

CallSystem.gc()It is actually equivalent to calling: Runtime. getRuntime (). gc ()

Select E

3. The growHeap () function cannot be found in the API. I wonder if it does not exist.

Iii. java garbage collection (gc) Mechanism

Http://www.cnblogs.com/aigongsi/archive/2012/04/06/2434771.html

Http://www.cnblogs.com/aigongsi/archive/2012/04/13/2446166.html


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.