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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:24:12+00:00 2026-05-10T20:24:12+00:00

I was reading Java Platform Performance (sadly the link seems to have disappeared from

  • 0

I was reading Java Platform Performance (sadly the link seems to have disappeared from the internet since I originally posed this question) and section A.3.3 worried me.

I had been working on the assumption that a variable that dropped out of scope would no longer be considered a GC root, but this paper appears to contradict that.

Do recent JVMs, in particular Sun’s 1.6.0_07 version, still have this limitation? If so, then I have a lot of code to analyse…

I ask the question because the paper is from 1999 – sometimes things change, particularly in the world of GC.


As the paper is no longer available, I’d like to paraphrase the concern. The paper implied that variables that were defined inside a method would be considered a GC root until the method exited, and not until the code block ended. Therefore setting the variable to null was necessary to permit the Object referenced to be garbage collected.

This meant that a local variable defined in a conditional block in the main() method (or similar method that contained an infinite loop) would cause a one-off memory leak unless you nulled a variable just before it dropped out of scope.

The code from the chosen answer illustrates the issue well. On the version of the JVM referenced in the document, the foo object can not be garbage collected when it drops out of scope at the end of the try block. Instead, the JVM will hold open the reference until the end of the main() method, even though it is impossible for anything to use that reference.

This appears to be the origin of the idea that nulling a variable reference would help the garbage collector out, even if the variable was just about to drop out of scope.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T20:24:12+00:00Added an answer on May 10, 2026 at 8:24 pm

    This code should clear it up:

    public class TestInvisibleObject{   public static class PrintWhenFinalized{     private String s;     public PrintWhenFinalized(String s){       System.out.println("Constructing from "+s);       this.s = s;     }     protected void finalize() throws Throwable {       System.out.println("Finalizing from "+s);     }      }   public static void main(String[] args) {     try {         PrintWhenFinalized foo = new PrintWhenFinalized("main");     } catch (Exception e) {         // whatever     }     while (true) {       // Provoke garbage-collection by allocating lots of memory       byte[] o = new byte[1024];     }    } } 

    On my machine (jdk1.6.0_05) it prints:

    Constructing from main

    Finalizing from main

    So it looks like the problems has been fixed.

    Note that using System.gc() instead of the loop does not cause the object to be collected for some reason.

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

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'd want the Observer Pattern for allowing other objects to… May 11, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer Check out the following tutorials: Edit Multiple Railscast Nested Object… May 11, 2026 at 11:30 pm
  • Editorial Team
    Editorial Team added an answer You could try with PyCallGraph From its documentation: Python Call… May 11, 2026 at 11:30 pm

Related Questions

I was reading an article on TheServerSide on ployglot programming on the Java platform
I've been reading up on so-called data grid solutions for the Java platform including
After reading Practical Common Lisp I finally understood what the big deal about macros
I'm thinking of choosing Adobe AIR as the client-side implementation technology for an upcoming

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.