In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the "new" operator. The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed
The memory for new objects is allocated on the heap at run time. Instance variables live inside the object in which they are declared.
Stack is where the method invocations and the local variables are stored. If a method is called then its stack frame is put onto the top of the call stack. The stack frame holds the state of the method including which line of code is executing and the values of all local variables. The method at the top of the stack is always the current running method for that stack. Threads have their own call stack.
As said earlier in Java objects are created in the heap. The programming language does not offer the possibility to let the programmer decide if an objects should be generated in the stack. But in certain cases it would be desirable to allocate an object on the stack, as the memory allocation on the stack is cheaper then the memory allocation in the heap, deallocation on the stack is free and the stack is efficiently managed by the runtime.
The JVM uses therefore internally escape analysis to check if an object is used only with a thread or method. If the JVM identify this it may decide to create the object on the stack, increasing performance of the Java program.
(http://www.ibm.com/developerworks/java/library/j-nativememory-linux/)
-XX:MaxHeapFreeRatio
and see if that solves your problem. – truthealitytop
shows virt size as more than 1GB and res size less than 50 MB. The virt/res ratio is thus really high. Heap dumps with jmap or the-XVerboseGC
switch show that the heap size is very small (less than 50 MB). How can I find out what is taking the non-heap memory? Thers is some socket IO involved usnig NIO, but I need evidence and need to track any memory leaks/ find roots. – CruiZen