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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:48:25+00:00 2026-05-21T22:48:25+00:00

I suppose that a program like this… class Test { public static void main(String[]

  • 0

I suppose that a program like this…

class Test {
    public static void main(String[] args) {
        new Test();
        System.out.println("done");
    }

    protected void finalize() {
        System.out.println("this object is known to never be referenced.");
    }
}

…may possibly output "this object is known to never be referenced." before "done". (Correct me if I’m wrong here!)

Furthermore, it is easy for a compiler/JVM to detect “unread locals”. In the program below for instance, Eclipse notices that “The local variable t is never read“.

However would it be illegal for the JVM to output "this object is known to never be referenced." before "done" given the (.class version) of the program below?

class Test {
    public static void main(String[] args) {
        Test t = new Test();
        System.out.println("done");
    }

    protected void finalize() {
        System.out.println("this object is known to never be referenced.");
    }
}

Most documentation of garbage collection talk about reachability. Given the fact that t is never read, the object is obviously not “reachable”, or?

References to the JLS are appreciated.

  • 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-21T22:48:26+00:00Added an answer on May 21, 2026 at 10:48 pm

    In 12.6.1 of the Java Language Specification says:

    12.6.1 Implementing Finalization

    Every object can be characterized by two
    attributes: it may be reachable,
    finalizer- reachable, or unreachable,
    and it may also be unfinalized,
    finalizable, or finalized. A reachable
    object is any object that can be
    accessed in any potential continuing
    computation from any live thread.
    Optimizing transformations of a
    program can be designed that reduce
    the number of objects that are
    reachable to be less than those which
    would naively be considered reachable.

    For example, a compiler or code
    generator may choose to set a variable
    or parameter that will no longer be
    used to null to cause the storage for
    such an object to be potentially
    reclaimable sooner.

    The last phrase seems to me covering exactly the case you are asking about. The variable t can be set to null implicitly before the end of the scope, therefore making the object unreachable.

    This in C++ would be a disaster because a lot of code depends on exact destruction timing at the end of scope (e.g. for locks).

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

Sidebar

Related Questions

Suppose that I have a Java class with a static method, like so: class
Suppose I have a function in a single threaded program that looks like this
Suppose I have an SConstruct file that looks like this: env = Environment() env.Program(a,
Suppose that I have a Java program within an IDE (Eclipse in this case).
Suppose I define a union like this: #include <stdio.h> int main() { union u
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
Consider this example The Interface interface IBusinessRules { string Perform(); } The Inheritors class
Suppose I develop an application with the logic as a CLI program that can
I'm making a program that makes a fractal, and the user is suppose to
Suppose that a group wants to encrypt some information, then share the encryption key

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.