I ran into an error when one of our server applications was using more and more memory every second, and I was able to filter out a short example that still shows this behavior:
public class TestGetLastModifiedTime { private static final Path PATH = Paths.get("D:\\test.txt"); private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(1); public static void main(String[] args) { SCHEDULER.scheduleAtFixedRate(() -> getLastModifiedTime(), 0, 1, TimeUnit.SECONDS); } private static void getLastModifiedTime() { try { FileTime lastModifiedTime = Files.getLastModifiedTime(PATH); } catch (IOException ex) { throw new UncheckedIOException(ex); } } }
Works on Windows 8.1 and Java 8u20.
Through VisualVM, I noticed that the maximum heap size does not grow and that the heap continues to grow. At the same time, I observe in the Windows task manager that the called java.exe process continues to use (reserve) more memory every second.
The interesting part is that when I run GC from VisualVM, all the heap memory used gets reset to almost zero, and the used memory of the java.exe process does not decrease, as expected, since it is considered to be backup.
However , after the GC was done, memory usage is still increasing every second, and now, of course, there is enough free space for the heap.
Metaspasia is also not affected.
For me, it really smells and looks like the JVM has a memory leak.
Can someone help me and explain what is going on here?
skiwi
source share