Interview question: "Can you talk about when the Java GC was, what to do and what to do?" ”

Source: Internet
Author: User

Interview Topics:
The people of the Earth know that Java has a thing called the garbage collector, it lets the object created do not need to be like c/cpp, delete, free off, you can talk about:

When was the GC, and what did it do to something?

The above is considered as three questions, the following one analysis:

question one answer : When?
1. When the system is idle.
Analysis: This answer accounts for about 30%, in general I will be ready to turn to other topics, such as algorithms, such as SSH to see if you can explore other aspects of his good.

2. The system itself decides, unpredictable time/call System.GC ().
Analysis: This answer accounted for about 55%, most of the fresh students can answer this answer, at least not a mistake is it, the follow-up should be broken down in the end is the language of the expression lead to the answer is too general, or itself only such a vague understanding.

3. Can say the new generation, the old generation structure, can propose minor gc/full GC
deep JVM virtual Machine . This part is less than 10%.

4. It can explain the trigger condition of minor gc/full GC, the trigger condition of oom, and reduce the tuning strategy of GC.
    Analysis: List Some of the answers I expected: ... Can answer that this stage will bring me higher expectations, of course, the interview when normal people will not remember the spelling of each parameter, I wrote this paragraph when I also turned over the manual. The answer to this section is less than 2%.

summary: Programmers cannot control time specifically, the system calls System.GC () at unpredictable times function, of course, can be adjusted by tuning, with Newratio controls the proportions of NewObject and Oldobject, with maxtenuringthreshold  control The number of times the oldobject is entered, causing the oldobject storage space to delay to full GC, which causes the timer to cause GC time delay oom Time delay

question two answer: what is the right thing ?
1. Objects that are not used.
    Analysis: the equivalent of no answer, the question is asking what object is the "unused object". accounted for about 30%.
2. An object that has an empty object/reference count that is out of scope.
    Analysis: The 2 answers stood at 60%, a fairly high percentage, and it was estimated that the teacher taught Java when the school taught it. The first answer does not solve my question, how exactly does the GC determine which objects are not in scope? As for the reference count to determine whether the object can be collected, I can add one of the following example to let the interviewer analyze Obj1, OBJ2 will be GC off?

class c{
          public Object x;
   }
    c obj1, obj2 = new C ();
    obj1.x = obj2;
    obj2.x = obj1;
    obj1, obj2 = null;

3. Search from GC root, search for objects not found.
    Analysis: Root object lookup, tag is pretty good, less than 5% people can answer this step, it is estimated that the way of reference counting too "deep in the hearts of the public" The Basically you can get all the points for this problem.
    PS: There are candidates in this question to add strong references, weak references, soft references, phantom reference differences, etc., is not the answer I want to ask, but can add points.

4. cannot be searched from root, and after the first mark, cleanup, there is still no Resurrection object.
Analysis: I look forward to the answer. But it's true that very few interviewers will answer that, so in my mind I answer the 3rd I give all the points.
Summary: Objects that are out of scope or reference count are empty, search for objects that cannot be found from GC root, and are marked, cleaned, and still have no resurrected objects.

question three answers: What to do?
1. Delete unused objects, freeing up memory space.
    Analysis: 1th with question 2. 40%.
2. Add some examples such as stop other threads from executing, running finalize, and so on .
    analysis: At least some of the problems have materialized, if like answer 1 I can hardly find the topic in the answer to continue to expand, about 40% of the people.
    added a little digression, the answer I feared most during the interview was " I can't say this question, but when I hit the internet, I could do it . Do program development really is not to exercise anise beans "anise" There are several ways, do not memorize I agree, I will not correct grammar, words, but how much you say a thought ah, to directly answer an Internet search, I have no way to get the information can be evaluated candidates, it is difficult to continue to explore the topic from the answer to discuss. > We recommend that you try to answer the areas you are familiar with and discuss , to show the interviewer the best side.

3. Can say what the new generation is doing is replication cleanup, from Survivor, to Survivor is what to do, the old age is to mark clean up, Mark clean up after the fragment to do not tidy, copy cleanup and tag cleanup have what advantages and disadvantages.
Analysis: Also read the "Deep JVM virtual machine" Basic can answer this degree, in fact, to this extent I have been more than expected. Also less than 10%.
4. In addition to 3, can also be clear serial, parallel (collation/Not defragment), CMS, such as the role of the collector can be the age, characteristics, advantages and disadvantages, and can explain the control/adjustment of the collector selection method.
Analysis: The 4th with the above 2 questions.
Summary: Delete unused objects, reclaim memory space, run the default finalize, and of course the programmer wants to invoke the dipose call to free resources such as file handle, the JVM uses from survivor, to survivor flag it clean, The object can also be resurrected after it is serialized.
Do not say that Google under the Internet, even say that they have previously encountered such a problem is how to deal with the knowledge of the idea, and then can ask the examiner, so that the technical type of the examiner for how to continue the topic and you have no words, hehe.

Transferred from: http://jeromecen1021.blog.163.com/blog/static/18851527120117274624888/

Interview question: "Can you talk about when the Java GC was, what to do and what to do?" ”

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.