Results 1 to 2 of 2
  1. #1
    adurga is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Object cleaning by Garbage Collector

    Please go through this question. I am thinking of option C where o has been assigned another new Object. Can somebody explain why the answer will be line 8?

    Thanks

    <code>
    Q: 01 Given:
    1. public class GC {
    2. private Object o;
    3. private void doSomethingElse(Object obj) { o = obj; }
    4. public void doSomething() {
    5. Object o = new Object();
    6. doSomethingElse(o);
    7. o = new Object();
    8. doSomethingElse(null);
    9. o = null;
    10. }
    11. }
    <code>

    When the doSomething method is called, after which line does the Object
    created in line 5 become
    available for garbage collection?
    A. Line 5
    B. Line 6
    C. Line 7
    D. Line 8
    E. Line 9
    F. Line 10
    Answer: D

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default Re: Object cleaning by Garbage Collector

    Look at what doSomethingElse does.
    Especially the calls to it on lines 6 and 8.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Garbage Collector
    By giorgi in forum New To Java
    Replies: 27
    Last Post: 05-20-2011, 10:09 AM
  2. about garbage collector
    By sudharani in forum New To Java
    Replies: 1
    Last Post: 04-25-2011, 11:25 AM
  3. How can I see the impression of the Garbage Collector?
    By Zamioculcas in forum New To Java
    Replies: 3
    Last Post: 04-01-2011, 02:34 PM
  4. When does the Garbage Collector pick up an object?
    By nolsen01 in forum New To Java
    Replies: 5
    Last Post: 02-27-2010, 03:32 PM
  5. Q about Garbage Collector
    By m00nchile in forum New To Java
    Replies: 4
    Last Post: 02-05-2010, 05:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •