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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:14:55+00:00 2026-05-18T04:14:55+00:00

is there a way to check if an object can be fetched by the

  • 0

is there a way to check if an object can be fetched by the garbage collector?

Somewhere in my code I’ve got a reference to an object:

MyObject mo = myObject;

Then, via Eclipse Debugger, I get the objects memory location. Afterwards, I set the reference null:

mo = null;

Is there any way to check if the previously referenced object is now suitable for garbage collection or if there’s somewhere another reference to it?

Thanks a lot,

Stefan

  • 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-18T04:14:55+00:00Added an answer on May 18, 2026 at 4:14 am

    You cannot do this at runtime with an arbitrary object, and in fact it’s not fully possible to do this deterministically. However, there are two options that may be suitable depending on your needs:

    1. Take a heap dump after you set the reference to null, and then load it up in a heap analyzer tool such as jhat or a profiler that supports this. These tools should let you traverse the path from the GC roots and thus check if your object is still reachable or not.
    2. Wrap the object in a PhantomReference with a given ReferenceQueue. When the reference is enqueued, you know that the object has been garbage collected. (Unfortunately, if the reference is unqueued it could be because the object is still reachable, or it could be because the GC just hasn’t inspected the object yet. As with all GC-related questions, garbage collection is not a deterministic process!)

    On the whole though, I agree that the best option is to be aware of memory leak issues and design your application to avoid them. If you do have a memory leak it should be obvious enough, and you can then focus your energies on finding the problem (again by dumping and analysing the heap for objects that are incorrectly reachable).

    The steps above are relatively time-consuming, and shouldn’t be something that you do after every change just to reassure yourself, but rather are tools you’d use to investigate a specific problem.

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

Sidebar

Related Questions

Is there a simple way to check the type of an object? I need
Is there a way in java to check if a specific object is in
Is there a way to check if some gem is currently installed, via the
Is there any way to check for identity (i.e. being exactly the same object,
Is there a way that you can check the javascript used on an html
Is there a way to check if a java Date object is Monday? I
Is there a nice way to check whether object o is a builtin Python
is there a way to check the type of an object in javascript against
Given a reference to a method, is there a way to check whether the
Is there a way to check what columns are there in mysql syntax? For

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.