Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8290092

Temporary files are kept when call Clipboard.getSystemClipboard().getImage()

XMLWordPrintable

    • b04
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      javafx18.0.1/Win10/Java18.0.1

      A DESCRIPTION OF THE PROBLEM :
      One temporary file like "~DF9C122A94A842C2B6.TMP" is created for each calling of Clipboard.getSystemClipboard().getImage(). These files are not removed automatically even after call System.gc() or exit the application. This means they occupy space of Java temporary path continually.
      Example, size of temporary file is 32+ MB on my platform. When my application is monitoring images in system clipboard, it calls Clipboard.getSystemClipboard().getImage() in a interval like 1 second, which write 32+ MB file in every second, then 120G space is eaten up after some time.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Define a button to look at image in system clipboard, like following:
      @FXML
       public void refreshAction() {
              Clipboard clipboard = Clipboard.getSystemClipboard();
              if (!clipboard.hasImage()) {
                  return;
              }
              clipboard.getImage();
          }

      2) Click this button, and watch files created under Java temporary path(System.getProperty("java.io.tmpdir")).
      3) Call System.gc() and check whether the temporary files are cleared.
      4) Exit the application and check whether the temporary files are cleared.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Temporary files should be cleared automatically.
      ACTUAL -
      Temporary files are persistent and occupy space of Java temporary path continually.

      CUSTOMER SUBMITTED WORKAROUND :
      Call following before and after Clipboard.getSystemClipboard().getImage().

      public static void clearTmpClips() {
              try {
                  System.gc();
                  File path = new File(System.getProperty("java.io.tmpdir"));
                  File[] files = path.listFiles();
                  if (files == null) {
                      return;
                  }
                  for (File file : files) {
                      try {
                          if (file.isFile() && file.getName().endsWith(".TMP")) {
                              FileUtils.deleteQuietly(file);
                          }
                      } catch (Exception e) {
                      }
                  }
              } catch (Exception e) {
              }
          }


      FREQUENCY : always


        1. App.java
          0.7 kB
        2. JavaFXSnapshot.java
          2 kB
        3. primary.fxml
          1 kB
        4. PrimaryController.java
          1 kB

            lkostyra Lukasz Kostyra
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: