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

  • Home
  • SEARCH
  • 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 9251789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:47:18+00:00 2026-06-18T10:47:18+00:00

Here I have a Java doubt regarding the Garbage Collection: protected class Robocop {

  • 0

Here I have a Java doubt regarding the Garbage Collection:

protected class Robocop {
Integer weight = 200;

Robocop attent(Robocop rb) {
rb = null;
return rb;
}
public static void main(String[] args) {
System.out.println("indeed the solution is behind the corner);

Robocop rb1 = new Robocop();

Robocop rb2 = new Robocop();

Robocop rb3 = rb1.attent(rb2);

rb1 = null;

}
}

How many objects do you reckon are going to be eligible for GC?

My take on this, would be 4 object to be garbage collected rb3, rb1 and the related Integer wrapper instance variables.

  • 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-18T10:47:19+00:00Added an answer on June 18, 2026 at 10:47 am

    Inside your method you could as well just return null since you get a copy of reference as argument to your method, not the original reference itself. Thus, you cannot modify original reference inside of your method. You can only modify the object this reference refers to.

    Right at the end of main, 2 objects will be eligible for GC: one Robocop (with one Integer inside).

    After main has finished, JVM will just shut down (in your case) and no GC will happen.

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

Sidebar

Related Questions

I have some question over here regarding the java garbage collector. First let me
Here is simplified version of my requirement I have a java class say Processor
Here is the piece of code that I have used for Java 5.0 TreeSet<Integer>
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
Referring here A is a precompiled Java class (I also have the source file)
We have system here that uses Java JNI to call a function in a
I have a simple java project (adapted from the example here ), which is
i found many related questions here. I have a simple java program . it
I have a pretty monstrous Java app in development here. As of now, it's
I have a problem with a specific java client library. Here is the situation:

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.