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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:03:01+00:00 2026-05-12T07:03:01+00:00

I was just digging around in the commons-io library and found this: Keeps track

  • 0

I was just digging around in the commons-io library and found this:

Keeps track of files awaiting deletion, and deletes them when
an associated marker object is reclaimed by the garbage collector.

This can be found in the documentation for the FileCleaningTracker object.

Now I am just curious how I can do this by myself? How can my code detect when an object is reclaimed by the garbage collector?

  • 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-12T07:03:01+00:00Added an answer on May 12, 2026 at 7:03 am

    According to the source code, it uses the PhantomReference class. According to the documentation:

    Phantom reference objects, which are enqueued after the collector determines that their referents may otherwise be reclaimed. Phantom references are most often used for scheduling pre-mortem cleanup actions in a more flexible way than is possible with the Java finalization mechanism.

    If the garbage collector determines at a certain point in time that the referent of a phantom reference is phantom reachable, then at that time or at some later time it will enqueue the reference.

    In order to ensure that a reclaimable object remains so, the referent of a phantom reference may not be retrieved: The get method of a phantom reference always returns null.

    Unlike soft and weak references, phantom references are not automatically cleared by the garbage collector as they are enqueued. An object that is reachable via phantom references will remain so until all such references are cleared or themselves become unreachable.

    The PhantomReference constructor accepts two arguments:

    referent – the object the new phantom reference will refer to

    q – the queue with which the reference is to be registered, or null if registration is not required

    The q argument is an instance of the ReferenceQueue class. The PhantomReference will be added to this ReferenceQueue when it’s referent becomes phantom reachable. When this happens, you can retrieve the PhantomReference by using the poll() or remove() methods of the ReferenceQueue class.

    For example:

    T objectToWatch = ...;
    ReferenceQueue<T> referenceQueue = new ReferenceQueue<T>();
    new PhantomReference<T>(objectToWatch, referenceQueue);
    
    // Later on, probably in another thread...
    Reference<? extends T> nextReference = referenceQueue.remove();
    // Tidy up!
    

    Note: PhantomReference has sibling classes named SoftReference and WeakReference that may also be of use. The relationship between these are documented in the java.lang.ref package documentation.

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

Sidebar

Related Questions

So, I was just digging around Reflector trying to find the implementation details of
I have been digging around on this site and googling for a while now
I've been digging around everywhere and I can't seem to figure this out. It's
I did some digging around about this, but nothing really seems to answer my
Today I was digging with TPL and found a new class Task.Now I just
Please bear with me, I've just started digging into this whole CPU thing. The
I'm just digging a bit into Haskell and I started by trying to compute
I'm just digging into the gcc manual and some things are still unclear to
I have just started digging into JavaFX and have a requirement that I am
So I just started digging into web tech, and I'm stuck on the concept

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.