Files.list().forEach() is observed to leak native memory (heap) on Windows when iterating large file hierarchy.
When native heap is inspected, it is full of file names which are being iterated.
How to reproduce:
$ java -jar test-leak.jar -prepare <folder>
$ java -jar test-leak.jar L <folder>
-prepare creates a deep hierarchy of files.
The test contains alternative for-loop based file iterator, which doesn't leak:
$ java -jar test-leak.jar H <folder>
The problem was reported by Dmitry Sviridov.
When native heap is inspected, it is full of file names which are being iterated.
How to reproduce:
$ java -jar test-leak.jar -prepare <folder>
$ java -jar test-leak.jar L <folder>
-prepare creates a deep hierarchy of files.
The test contains alternative for-loop based file iterator, which doesn't leak:
$ java -jar test-leak.jar H <folder>
The problem was reported by Dmitry Sviridov.
- duplicates
-
JDK-8062798 Files.list - file handle leak
-
- Closed
-
- relates to
-
JDK-8274412 Add a method to Stream API to consume and close the stream without using try-with-resources
-
- Open
-