Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:52:54+00:00 2026-06-11T04:52:54+00:00

consider this sample code: 1. public class GC { 2. private Object o; 3.

  • 0

consider this sample code:

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. }

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

why D? it’s true that when Line 6 is executed the object created in Line 5 is now referenced by the instance var o and the local var o and when Line 8 is executed the object now is referenced by only the local ref var o, so why the answer is D and what happens after Line 9 is executed?? thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:52:56+00:00Added an answer on June 11, 2026 at 4:52 am

    The main reason this question is confusing IMO is that there are 2 variables named o. One is the instance variable o and the other is the local variable o inside method doSomething().

    Time            instance var o    local var o
    Before Line 5:            null               
    Line 5:                   null       Object#1
    Line 6:               Object#1       Object#1
    Line 7:               Object#1       Object#2
    Line 8:                   null       Object#2   <- No more references to Object#1
    

    So on (or after executing) line 8, Object#1 is eligible for collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code sample: public class Human { public string Value { get; set;}
Consider this code sample: public abstract class Parent { public int val; public Parent()
Consider the following sample code: class Base { public: void f(); virtual void vf();
Consider this sample class, class TargetClass { private static String SENSITIVE_DATA = sw0rdfish; private
Consider this simple example - public class Person { private String name; private Date
Consider the following sample code: #include <iostream> using namespace std; class base { public:
Consider the code: class UPDServer { //start listener public void start() { UdpClient listener
Consider the sample code below: #include <iostream> using namespace std; class core { public:
I have the following code class sample { public void update(List l) { l
Consider this simple AS3 class. package { import flash.display.Sprite; import flash.display.MovieClip; public class MySprite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.