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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:36:09+00:00 2026-05-20T21:36:09+00:00

I have created a file from my java programming, and am logging some data

  • 0

I have created a file from my java programming, and am logging some data use Apache Commons Logging API, specifically the Log4j implementation.

After the logging has been done, I am setting the reference to the Log class as null. When I now try to delete the file to which I have been logging, File.delete() returns false.

Deleting the file from windows explorer during debugging (at the point just before File.delete() is called), I get the notification “cannot delete: being used by another program”.

There are no open dependencies on the file from my code (all streams are closed). The only object that could be accessing the file is the Log object, which I have set to null before calling File.delete()

Is there anyway I can see what specific object is holding a reference to the file resource?
Is there any other way to force the Log object to release resource, other than setting it to null?
Can I force a delete on the file?

  • 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-20T21:36:10+00:00Added an answer on May 20, 2026 at 9:36 pm

    Just setting the variable to null doesn’t force the object to be garbage collected. Also, there’s a chance that it’s registered in some sort of static map – you’d have to check the implementation to be sure. (I think some versions use weak references, but others don’t.)

    Is there any reason you have to delete the file right then? You might want to try File.deleteOnExit(), which may have a better chance of deleting the file – although it depends on exactly what the timing is like. (Also, beware of a possible memory leak if you call deleteOnExit repeatedly.)

    Could you just delete the file after the application has finished, or possibly on the next start-up?

    Alternatively, can you use a log implementation which rolls the files over – try to force a rollover, and then delete the old file?

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

Sidebar

Related Questions

I have a method that creates a MessageDigest (a hash) from a file, and
I have created a Python file to generate a Mandelbrot set image. The original
I have created a C# class file by using a XSD-file as an input.
I've got two PostgreSQL databases that have been created using the same sql file.
I have a batch file that was created for an Oracle database that I'm
I have a library I created, File mylib.c: #include <mylib.h> int testlib() { printf("Hello,
I have an Oracle database backup file (.dmp) that was created with expdp .
I have a berkeley db file (*.bdb) which is created by the C implementation(python
I have a single spool mbox file that was created with evolution, containing a
I am analyzing a .dmp file that was created and I have a call

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.