- I am creating temporary files in my application using
java.io.File.createTempFile()
. - While creating file, I have called
deleteOnExit()
for that File object.
This code is used in many scenarios in my application. Sometimes, the size of temp files is too large and so I have to delete it immediately after my job is completed. So I am calling File.delete()
for some objects.
Now the problem is, when I delete the file using delete()
function, the reference pointer is open for this deleted file(because of it being temp file(My opinion)). Because of this, I am facing memory leakage issue.
(Correct me if I am wrong on my above hypothesis)
I am facing high disk utilization on my environment, I found a discrepancy of over 30GB in the output of the 'df' and 'du' command ('df' looks at the stat of the FS itself whereas 'du' ignores deleted file descriptors).
- If I remove deleteOnExit(), I will have to take care of deleting all the objects manually. Doing this, my pointers are still remaining open(Used
lsof +al1
on linux to see open files) Why is this happening? - If I remove delete(), then I will have to wait until VM stops to get tempFiles deleted(which is a very rare case in Production Server). (Huge Space Utilization)
Is there any Solution on how I can remove file from deleteOnExit() list if I am manually deleting the file?