Temporary Files not getting removed

An AposeNative folder (with subfolders and files) is created in the TEMP area but not removed. Seeing this issue on Windows using Java 8 and Words 25.3. Expecting these files to be removed according to this post Changing the /tmp directory to other path which I realize is 10 years old.

@ssol2 We will check the issue and get back to you soon.

@ssol2
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSJAVA-3078

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@ssol2,

Unfortunately, in the current implementation of the native DLL loading and usage mechanism, it is impossible to clean up the temporary directory while the program is running because the JVM locks the temporary library file, preventing its deletion. As a solution, a new method (WORDSJAVA-3098) has been developed to allow manual cleanup of the temporary directory. However, this will only work if no native libraries have been used during your program’s execution. This cleanup method will be available in Aspose.Words for Java 25.6.

For now, as a temporary workaround, you can implement code to clean the temporary directory by retrieving its path via com.aspose.words.NativeLibSettings.getTmpDirectoryPath(). Below is an example code snippet to delete temporary files recursively:

...
private void deleteDirectoryRecursively(String directoryPath) throws IOException {
       Path path = Paths.get(directoryPath);

       if (!Files.exists(path)) {
           throw new NoSuchFileException("Directory does not exist: " + directoryPath);
       }

       Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
           @Override
           public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
               Files.delete(file);
               return FileVisitResult.CONTINUE;
           }

           @Override
           public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
               if (exc != null) {
                   throw exc;
               }
               Files.delete(dir);
               return FileVisitResult.CONTINUE;
           }
       });
   }
...

Usage:

...
// other code
deleteDirectoryRecursively(com.aspose.words.NativeLibSettings.getTmpDirectoryPath());
...