-
Bug
-
Resolution: Fixed
-
P2
-
6u10
-
b55
-
x86
-
windows_xp, windows_vista
-
Not verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2183123 | 6u18 | Pavel Porvatov | P2 | Closed | Fixed | b03 |
FULL PRODUCT VERSION :
tested on jre 1.6_10
ADDITIONAL OS VERSION INFORMATION :
Windows Vista 64Bit business..
though problem seems to appear on more os
A DESCRIPTION OF THE PROBLEM :
On using FileSystemView.getFiles() to retrieve all children of a directory the used memory shown by the OS rises. Though Heap and non Heap memory shown by jconsole stay the same.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
SSCCE given below ... just run it
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Simple demo should just print ount current ammount of files on the disc...
And not use much memory.
ACTUAL -
Memory usage of the java process rose by about 200 MiB per minute.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class LeakTest {
private static long counter = 0;
private static FileSystemView view = FileSystemView.getFileSystemView();
public static void main(String[] args) throws InterruptedException {
while (true) {
for (File f : File.listRoots()) {
if (f.isDirectory()) {
countFiles(f);
System.out.println("found: "+counter);
}
}
System.out.println("found Total: "+counter);
counter = 0;
Thread.sleep(1000);
}
}
private static void countFiles(File root) {
for (File f :view.getFiles(root, false)) {
if (f.isDirectory()) {
countFiles(f);
} else {
counter++;
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not a very good one:
Using the following method gives nearly the same behaviour... though FileSystemViews list files still shows different kind of files as visible then File.isHidden()
i.e. $Recycle.bin on Windows
private static File[] getFiles(File parent,boolean useHidden) {
File[] files = parent.listFiles();
if (files == null) return new File[0];
if (useHidden) {
int length = files.length;
for (int i = 0; i < length; i++) {
if (files[i].isHidden()) {
length--;
System.arraycopy(files, i+1, files, i, length-i );
}
}
if (length != files.length) {
File[] onlyVisible = new File[length];
System.arraycopy(files, 0, onlyVisible, 0, length);
return onlyVisible;
}
}
return files;
}
tested on jre 1.6_10
ADDITIONAL OS VERSION INFORMATION :
Windows Vista 64Bit business..
though problem seems to appear on more os
A DESCRIPTION OF THE PROBLEM :
On using FileSystemView.getFiles() to retrieve all children of a directory the used memory shown by the OS rises. Though Heap and non Heap memory shown by jconsole stay the same.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
SSCCE given below ... just run it
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Simple demo should just print ount current ammount of files on the disc...
And not use much memory.
ACTUAL -
Memory usage of the java process rose by about 200 MiB per minute.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import javax.swing.filechooser.FileSystemView;
public class LeakTest {
private static long counter = 0;
private static FileSystemView view = FileSystemView.getFileSystemView();
public static void main(String[] args) throws InterruptedException {
while (true) {
for (File f : File.listRoots()) {
if (f.isDirectory()) {
countFiles(f);
System.out.println("found: "+counter);
}
}
System.out.println("found Total: "+counter);
counter = 0;
Thread.sleep(1000);
}
}
private static void countFiles(File root) {
for (File f :view.getFiles(root, false)) {
if (f.isDirectory()) {
countFiles(f);
} else {
counter++;
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Not a very good one:
Using the following method gives nearly the same behaviour... though FileSystemViews list files still shows different kind of files as visible then File.isHidden()
i.e. $Recycle.bin on Windows
private static File[] getFiles(File parent,boolean useHidden) {
File[] files = parent.listFiles();
if (files == null) return new File[0];
if (useHidden) {
int length = files.length;
for (int i = 0; i < length; i++) {
if (files[i].isHidden()) {
length--;
System.arraycopy(files, i+1, files, i, length-i );
}
}
if (length != files.length) {
File[] onlyVisible = new File[length];
System.arraycopy(files, 0, onlyVisible, 0, length);
return onlyVisible;
}
}
return files;
}
- backported by
-
JDK-2183123 Memory Leak on using getFiles of FileSystemView
- Closed
- duplicates
-
JDK-6788496 JFileChooser.showOpenDialog leaks native memory on Windows
- Closed
- relates to
-
JDK-6997102 Test case has hard code, so that applet thread threw exception
- Closed
-
JDK-7059834 javax/swing/JFileChooser/6868611/bug6868611.java failed on windows vista x64
- Closed