< prev index next >
src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
Print this page
rev 17684 : JDK-8175015: Fixed the memory leak that is happening due to listFiles, and also
improved the performance for isFileSystemRoot.
@@ -441,31 +441,26 @@
}
public boolean isFileSystemRoot(File dir) {
//Note: Removable drives don't "exist" but are listed in "My Computer"
if (dir != null) {
- Win32ShellFolder2 drives = getDrives();
+
if (dir instanceof Win32ShellFolder2) {
Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
- if (sf.isFileSystem()) {
- if (sf.parent != null) {
- return sf.parent.equals(drives);
- }
- // else fall through ...
- } else {
- return false;
- }
+
+ return (sf.isFileSystem() && sf.parent != null &&
+ sf.parent.equals(Win32ShellFolder2.listRoots()));
}
String path = dir.getPath();
if (path.length() != 3 || path.charAt(1) != ':') {
return false;
}
- File[] files = drives.listFiles();
+ File[] roots = Win32ShellFolder2.listRoots();
- return files != null && Arrays.asList(files).contains(dir);
+ return roots != null && Arrays.asList(roots).contains(dir);
}
return false;
}
private static List<Win32ShellFolder2> topFolderList = null;
@@ -559,10 +554,15 @@
*/
Thread thread = new Thread(
ThreadGroupUtils.getRootThreadGroup(), comRun, name,
0, false);
thread.setDaemon(true);
+ /* This is important, since this thread running at lower priority
+ leads to memory consumption when listDrives() function is called
+ repeatedly.
+ */
+ thread.setPriority(Thread.MAX_PRIORITY);
return thread;
});
return comThread;
}
< prev index next >