Closed jpountz closed 11 years ago
I think the removal of temporary files should be a best effort approach, i.e. there's not much that can be done if the running application is killed. That said, I'm not sure File.deleteOnExit will work in either of the cases you described. But at least for the first one we can get around it by adding a shutdown hook to do the clean up (http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)). I don't have access to a Windows computer where I can test this.
I tend to agree to the best effort approach. Looking at openjdk sources, it looks like File.deleteOnExit adds a shutdown hook (http://hg.openjdk.java.net/icedtea/jdk7/jdk/file/10672183380a/src/share/classes/java/io/DeleteOnExitHook.java, http://hg.openjdk.java.net/icedtea/jdk7/jdk/file/10672183380a/src/share/classes/java/io/File.java) so both approaches should work the same way?
I added comment to LZ4Factory to say that on some OS, lz4-java may leave files in the temporary directory.
net.jpountz.util.Native.java first copies the shared library file to a temporary file, and then tries to call System.load. There is a call to File.deleteOnExit to remove it, but does it work: