Question 11th (garbage collection)

Source: Internet
Author: User

First, the runtime class

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 by means of a getRuntime method.

The application cannot create its own instance of the Runtime class.

GetRuntime ()
Returns the run-time object associated with the current Java application. Runtimemost methods of a class are instance methods, and they must be called according to the current run-time object.

Return:
the object associated with the current Java application Runtime .

freememory ()
Returns the amount of idle memory in a Java virtual machine. Calling gc a method may result freeMemory in an increase in the return value.
Return:
The approximate total amount of current available memory to be used by the future allocation object, in bytes.
(A wrong)

GC ()
run the garbage collector. Calling this method means that the Java virtual machine has made some effort to reclaim unused objects so that the memory currently occupied by these objects can be reused quickly. When control returns from a method call, the virtual machine has done its best to reclaim all discarded objects.

gcthe name represents the garbage collector. The virtual machine automatically performs the recycling process on a separate thread as needed, even without explicitly invoking the gc method.

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

GC is a non-static method,

So call the time with Runtime.getruntime (). GC ();

b wrong

Second, System class

GC ()
Run the garbage collector.

The invocation gc method implies that the Java virtual machine has made some effort to reclaim unused objects so that the memory currently occupied by these objects can be reused quickly. When control is returned from a method call, the virtual machine has tried its best to reclaim space from all discarded objects.

The call is System.gc() actually equivalent to the call: Runtime.getruntime (). GC ()

Select E

third, growheap () This function can not be found in the API, do not know whether there is no

Third, 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


Question 11th (garbage collection)

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.