In my app I'm writing a file to store some execution info and once the execution is done I want to delete the temp file. The issue is even after file close or flush by streams I cannot delete the file. I tried
Thread.sleep(1000);
file.delete();
and that didn't delete the file either. I then created a while loop
while(!file.delete())
Thread.sleep(1000);
and it was looping forever. I then added
System.gc();
file.delete();
and it worked!!!
I have verified that I have gracefully closed or flushed the file. I want to know why my code worked with System.gc()?