14

Possible Duplicate:
Why does an empty Java program consume memory?

Why an absolutely empty Java application continuously consumes memory? The app:

public class Dummy {
    public static void main(String[] args) throws IOException {
        System.in.read();
    }
}

Or even:

public class Dummy {
    public static void main(String[] args) throws InterruptedException {
        synchronized (Thread.currentThread()) {
            Thread.currentThread().wait();
        }
    }
}

Heap state:

Empty Java app heap state

Updated: IOException fix.

Community
  • 1
  • 1
tilex
  • 1,644
  • 1
  • 17
  • 32
  • 12
    Is it possible that the act of you monitoring it is creating objects? Just a thought. – Jon Skeet Mar 11 '12 at 13:40
  • 1) Your program is not empty. 2) All running programs automatically get ***some*** amount of memory. For the minimum java heap size please refer to [this other SO post](http://stackoverflow.com/questions/4667483/how-is-the-default-java-heap-size-determined). – Perception Mar 11 '12 at 13:40
  • 2
    Presumably System.in.read is doing stuff "under the covers". Try Thread.wait instead. – Hot Licks Mar 11 '12 at 13:40
  • 1
    +1 BTW, `InterruptedException` should be `IOException`. – Eng.Fouad Mar 11 '12 at 13:41
  • Yes. `InterruptedException` has left from the previous version of the program where I've used `Thread.wait()` instead of `System.in.read()`. The result was the same: memory consumption. – tilex Mar 11 '12 at 13:47
  • Off-topic: What tool did you use to generate this graph? – Jakub Zaverka Mar 11 '12 at 13:52
  • jvisualvm. Located in JDK/bin. – tilex Mar 11 '12 at 13:53
  • 4
    Might be the Java VM. Just looking at the pattern it would make sense that that is the garbage collector firing off. – endy Mar 11 '12 at 13:53
  • Haven't found this question before posting. Sorry. – tilex Mar 11 '12 at 14:01
  • Odd that this was closed without anyone stating what the "exact duplicate" was. – Hot Licks Mar 11 '12 at 14:34

0 Answers0