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

FileSystemView.isDrive(File) memory leak on "C:\" file reference

    Details

    • Subcomponent:
    • Resolved In Build:
      b23
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) Client VM (build 25.121-b13, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 Enterprise

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Intel Core i5-6300
      16 GB RAM
      64 bit OS

      A DESCRIPTION OF THE PROBLEM :
      Using "FileSystemView.isDrive()" has a small memory leak when ran against a "C:\" file object.

      The more you run the method, the more the heap fills up with references to:
        "sun.awt.shell.Win32ShellFolder2"
        "sun.awt.shell.Win32ShellFolder2$FolderDisposer"



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached code with a "-Xmx16m" vm argument to limit the time until the memory is exhausted.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test should complete without a memory issue.
      ACTUAL -
      Root Exists: true
      Root Absolute Path: C:\
      Root Is Directory?: true
      0.1 % (25/50000) [Memory Used: 15,872 kb Free=13,011 kb Max: 15,872 kb]
      0.2 % (75/50000) [Memory Used: 15,872 kb Free=12,658 kb Max: 15,872 kb]
      0.3 % (125/50000) [Memory Used: 15,872 kb Free=12,393 kb Max: 15,872 kb]
      0.4 % (175/50000) [Memory Used: 15,872 kb Free=12,128 kb Max: 15,872 kb]
      0.5 % (225/50000) [Memory Used: 15,872 kb Free=11,863 kb Max: 15,872 kb]
      0.6 % (275/50000) [Memory Used: 15,872 kb Free=11,509 kb Max: 15,872 kb]
      ...
      5.6 % (2775/50000) [Memory Used: 15,872 kb Free=3,286 kb Max: 15,872 kb]
      5.7 % (2825/50000) [Memory Used: 15,872 kb Free=2,973 kb Max: 15,872 kb]
      5.8 % (2875/50000) [Memory Used: 15,872 kb Free=2,717 kb Max: 15,872 kb]
      5.9 % (2925/50000) [Memory Used: 15,872 kb Free=2,482 kb Max: 15,872 kb]
      6.0 % (2975/50000) [Memory Used: 15,872 kb Free=2,168 kb Max: 15,872 kb]
      6.1 % (3025/50000) [Memory Used: 15,872 kb Free=1,913 kb Max: 15,872 kb]
      6.2 % (3075/50000) [Memory Used: 15,872 kb Free=1,599 kb Max: 15,872 kb]
      6.3 % (3125/50000) [Memory Used: 15,872 kb Free=1,344 kb Max: 15,872 kb]
      6.4 % (3175/50000) [Memory Used: 15,872 kb Free=1,030 kb Max: 15,872 kb]
      6.5 % (3225/50000) [Memory Used: 15,872 kb Free=796 kb Max: 15,872 kb]
      6.6 % (3275/50000) [Memory Used: 15,872 kb Free=2,185 kb Max: 15,872 kb]
      6.7 % (3325/50000) [Memory Used: 15,872 kb Free=1,940 kb Max: 15,872 kb]
      6.8 % (3375/50000) [Memory Used: 15,872 kb Free=1,661 kb Max: 15,872 kb]
      6.9 % (3425/50000) [Memory Used: 15,872 kb Free=1,321 kb Max: 15,872 kb]
      7.0 % (3475/50000) [Memory Used: 15,872 kb Free=1,055 kb Max: 15,872 kb]
      7.1 % (3525/50000) [Memory Used: 15,872 kb Free=796 kb Max: 15,872 kb]
      7.2 % (3575/50000) [Memory Used: 15,872 kb Free=512 kb Max: 15,872 kb]
      7.3 % (3625/50000) [Memory Used: 15,872 kb Free=246 kb Max: 15,872 kb]
      7.4 % (3675/50000) [Memory Used: 15,872 kb Free=1,018 kb Max: 15,872 kb]
      7.5 % (3725/50000) [Memory Used: 15,872 kb Free=735 kb Max: 15,872 kb]
      7.6 % (3775/50000) [Memory Used: 15,872 kb Free=477 kb Max: 15,872 kb]
      7.7 % (3825/50000) [Memory Used: 15,872 kb Free=195 kb Max: 15,872 kb]
      7.8 % (3875/50000) [Memory Used: 15,872 kb Free=385 kb Max: 15,872 kb]
      7.9 % (3925/50000) [Memory Used: 15,872 kb Free=96 kb Max: 15,872 kb]
      8.0 % (3975/50000) [Memory Used: 15,872 kb Free=487 kb Max: 15,872 kb]
      8.1 % (4025/50000) [Memory Used: 15,872 kb Free=198 kb Max: 15,872 kb]
      8.2 % (4075/50000) [Memory Used: 15,872 kb Free=198 kb Max: 15,872 kb]
      8.3 % (4125/50000) [Memory Used: 15,872 kb Free=33 kb Max: 15,872 kb]
      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.io.WinNTFileSystem.normalize(WinNTFileSystem.java:107)
      at java.io.WinNTFileSystem.normalize(WinNTFileSystem.java:96)
      at java.io.File.<init>(File.java:279)
      at sun.awt.shell.ShellFolder.<init>(ShellFolder.java:52)
      at sun.awt.shell.Win32ShellFolder2.<init>(Win32ShellFolder2.java:295)
      at sun.awt.shell.Win32ShellFolder2$9.call(Win32ShellFolder2.java:717)
      at sun.awt.shell.Win32ShellFolder2$9.call(Win32ShellFolder2.java:680)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Win32ShellFolderManager2.java:547)
      at java.lang.Thread.run(Thread.java:745)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      The heap shows a large number of:

        "sun.awt.shell.Win32ShellFolder2"
        "sun.awt.shell.Win32ShellFolder2$FolderDisposer"



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.text.NumberFormat;

      import javax.swing.filechooser.FileSystemView;

      public class FSVTest {

          public static void main(String[] args) {
           test();
      }

          private static void test() {

           File root = new File("C:\\");

           System.out.println("Root Exists: " + root.exists());
           System.out.println("Root Absolute Path: " + root.getAbsolutePath());
           System.out.println("Root Is Directory?: " + root.isDirectory());

      FileSystemView fileSystemView = FileSystemView.getFileSystemView();
      NumberFormat nf = NumberFormat.getNumberInstance();

      int iMax = 50000;
      long lastPercentFinished = 0L;

      for (int i = 0; i < iMax; i++) {

      long percentFinished = Math.round(((i * 1000d) / (double) iMax));

      if (lastPercentFinished != percentFinished) {
      double pf = ((double) percentFinished) / 10d;
      String pfMessage = String.valueOf(pf) + " % (" + i + "/" + iMax + ")";

      long totalMemory = Runtime.getRuntime().totalMemory() / 1024;
      long freeMemory = Runtime.getRuntime().freeMemory() / 1024;
      long maxMemory = Runtime.getRuntime().maxMemory() / 1024;
      String memMessage = "[Memory Used: " + nf.format(totalMemory) + " kb Free=" + nf.format(freeMemory) + " kb Max: " + nf.format(maxMemory) + " kb]";

      System.out.println(pfMessage + " " + memMessage);
      lastPercentFinished = percentFinished;
      }

      boolean floppyDrive = fileSystemView.isFloppyDrive(root);
           boolean computerNode = fileSystemView.isComputerNode(root);

           // "isDrive()" seems to be the painful method...
           boolean drive = fileSystemView.isDrive(root);

      }
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kaddepalli Krishna Addepalli
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: