Java basics-005, java-005

Source: Internet
Author: User

Java basics-005, java-005
27. Purpose of garbage collection in Java and timing of garbage collection

The purpose of garbage collection is to identify and Discard unused objects to release and reuse resources.

If the object reference is set to null, the garbage collector does not immediately release the memory occupied by the object.

When garbage collection depends primarily on JVM. Refer to the http://www.cnblogs.com/lrh-xl/p/5292495.html

28. System. gc () and Runtime. gc ()

These two methods are used to prompt the JVM to perform garbage collection. However, whether to start garbage collection immediately or delay depends on the JVM.

The actions of these two methods are essentially the same.

29. finalize () method

When the Garbage Collector decides to recycle an object, it will run the finalize () method of the object. However, in Java, if the memory is sufficient, garbage collection may never be performed, that is, finalize () it may never be executed. Obviously, it is unreliable to close the work. (The time for garbage collection depends on the JVM type, the garbage collection algorithm adopted by JVM, and the memory allocation and collection policy ). the fianlize () method is mainly used to reclaim memory applied by special channels. java programs have garbage collectors, so there is usually no need for programmers to worry about memory problems, but there is a JNI (Java Native Interface) that calls non-Java programs (C/C ++ ), finalize () is to recycle this part of memory.

30. Java heap and permanent generation

The JVM heap is the runtime data zone, and all class instances and arrays are allocated memory on the heap. it was created at JVM startup. the memory occupied by objects is collected by the automatic memory management system, that is, the garbage collector.

Heap memory is composed of surviving and dead objects. The surviving objects are accessible to applications and will not be recycled, the dead objects are objects that are inaccessible to the application and are not recycled by the garbage collector. They occupy the memory until the Garbage Collector recycles these objects.

Understanding

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.