Java interview frequently test knowledge points

Source: Internet
Author: User
Tags garbage collection

1. In Java, when can objects be garbage collected?

When an object to the GC roots unreachable, in the next garbage collection cycle will attempt to reclaim the object, if the object overrides (five) Finalize () method, and the method re-assigned to a reference to achieve self-help effect, then this object will not be recycled, if not " Save, the object will be recycled.

How does the garbage collection mechanism work in 2.Java?

When an object is instantiated (because the garbage collection mechanism is in the heap), the first thing to do is to see if there is enough space in the Eden area, and if it is sufficient, the object is stored directly, not garbage collected, and if Eden Memory is full of minor GC (the function is to reclaim the garbage to free memory), To see if Eden memory is enough, if it's not enough, you need to see if the survivor area is enough memory (trying to save the Eden part of the active object in survivor), if enough, Save the Eden part of the active object in survivor, which is stored in Eden, if not enough, to see if the old age is enough memory, if enough, to save the survivor part of the active object in the old age, the Eden part active object is saved in Survivor, This object is stored in Eden, and if it is not enough, a full GC will be performed, and then the old generation will then be able to determine if the memory is sufficient, if not enough, if not enough (causing the JVM to not create a memory region for the new object in the Eden Zone), the OutOfMemoryError will be thrown.

Java interview frequently test knowledge points

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.