Geodepe
Geodepe

Reputation: 151

Why does Intellij Heap Memory Leak on Hello World with Thread.Sleep?

I noticed that heap memory usage was increasing on other programs, so I made this simple program to see if JConsole was reporting the same on simple HelloWorld application. I added a Thread.sleep() in a loop to keep the app alive for testing.

What is the source of this problem? Should I be concerned?

This chart shows my testing setup:

enter image description here

Here is the code I am using for testing:

public class Main {
public static void main(String[] args) {
    System.out.println("Hello World!");
    while(true)
    {
        try {
            System.out.print("Sleeping...");
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Working");
    }
}
}

This chart shows that the heap memory doubles within 15 minutes:

enter image description here

After 25 minutes I did see reclaimed memory but the same leak continued from there:

enter image description here

Is this just the way intellij behaves? Is the reclaimed memory enough to say this is not a leak?

Note: System is macOS High Sierra on MacBook Pro 2.8GHz 16 GB. IntelliJ Ultimate 2018.2.

Upvotes: 1

Views: 1038

Answers (1)

Geodepe
Geodepe

Reputation: 151

As Jacob suggested, this is entirely normal.

As Peter suggested, I tested with Java Mission Control and verified that the heap memory after successive garbage collections was fairly stable (It would be nice if I could hover over those lows to get exact values).

I still am concerned that such a small test program allocates 140MB on a regular basis. I would have expected something much much lower.

Here is JMC screenshot with findings:

enter image description here

Upvotes: 1

Related Questions