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 6822145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:37:43+00:00 2026-05-26T21:37:43+00:00

I just read this article: The Truth About Garbage Collection In section A.3.3 Invisible

  • 0

I just read this article: The Truth About Garbage Collection

In section “A.3.3 Invisible” it is explained how and when an object gets into the invisible state.

In the below code, the object assigned to the variable foo will become invisible after leaving the try/catch block and will remainly strongly referenced until the run method exits (which will never happen, because the while loop runs forever).

public void run() {
    try {
        Object foo = new Object();
        foo.doSomething();
    } catch (Exception e) {
        // whatever
    }
    while (true) { // do stuff } // loop forever
}

It is stated in this article:

However, an efficient implementation of the JVM is unlikely to zero
the reference when it goes out of scope.

Why is that not efficient?

My attempt at an explanation is as follows:

Say the stack for this method contains four elements, with the now invisible object being at the bottom.
If you want to collect the object instantly, you would have to pop and store three elements, pop and discard the fourth element and then push the three still valid elements back onto the stack.
If you collect the invisible object after control flow has left the run method, the VM could simply pop all four elements and discard them.

  • 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-05-26T21:37:44+00:00Added an answer on May 26, 2026 at 9:37 pm

    The local variables are not on the operand stack, but in the local variables area in the activation frame, accessed, in the case of references via aload and astore bytecodes and zeroing a local variable does not involve any pushing and popping.

    Zeroing is inefficient because it is not needed:

    • it would not cause an immediate garbage collection cycle
    • the zero may soon be overwritten by another value as dictated by the logic of the program.
    • going out of the scope means that the local variable is no longer part of the root set for garbage collection. As such what value it held immediately before going out of scope – zero or a valid reference – is immaterial; it won’t be examined anyway.

    EDIT:

    Some comments on the last statement.

    Indeed, at a bytecode level there are no scopes and a local variable slot may remain a part of the root set until the method returns. Of course, a JVM implementation can determine when a local variable slot is dead (i.e. all possible paths to method return either don’t access the variable or are stores) and don’t consider it a part of the root set, but it is by no means required to do so.

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

Sidebar

Related Questions

I already read many article about this issue in here, SO. I just want
I have just read this interesting article about the implementation details for various languages
I just read this article about the Entity Framework 4 (actually version 2). Entity
I was just having a quick read through this article (specifically the bit about
I've just read about @Resource annotation from this article ( http://www.infoq.com/articles/spring-2.5-part-1 ) and wish
I just read this post about why new-line warnings exist, but to be honest
Just finished read this post by Greg Young, where he is talking about Microsoft
I just started to read about this new technology... Does someone have some knowledge
I just read about HTML 5's WebSocket interface. How can I start trying this?
I have just read an article about the Curiously Recurring Template Pattern. And you

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.