At what line can this object be considered to be garbage collected. Java -


So my understanding is on Line 1, a new object has been created and it is referenced by obj, on line 2, And referencing the new object. Therefore, the object that we created on Line 1 is eligible for garbage collection because it is not referenced from any instance. But the answer to the examination question is on line 3. reason? Is the answer right?

  object obj = new object (); // line1 obj = new object (); // line2 obj = null; Edit: It is asking if the item created on Line 1 may be eligible for garbage collection. 

  • Aggressive dead code eradication The first object can eliminate allocation
  • A revised object class (such as through biotech instrumentation or bootstrap classloaders) can finally rebuild itself or hold indirectly over additional references < / Li>
  • Garbage Collection Atul Yesterday and it happens to be an indefinite point in the future, so when a thing can be inaccessible with Java code, it can not be collected by garbage until it is actually collected garbage.
    It may appear in a pile dump after all, which may be relevant if it contains security-sensitive data

I know that this is an academic question with a simple answer Supposedly If there is no rabbit out of our cap, even then the answer will still depend on the "X on the line" means that

/ Div> before or after the execution

Comments