3

While either IntelliJ or Eclipse are running, I can see how much heap they are using from inside the application from the progress bar at the bottom.. it always indicates a sub 512 MB value which the max size allocated on startup. Now in many cases, if I look from the OS (Linux) it says that the app is using about 1300 MB, I understand that the libraries, stack, memory mapped files, ... are not in the heap... But why is the difference that big? There is usually about 1GB difference...Why?

Thank you.

AhHatem
  • 1,415
  • 3
  • 14
  • 23
  • Use a tool to inspect the different memory sizes of your application. Using jconsole (which ships with your jdk) for example. See http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html for more information – jelle Dec 27 '11 at 10:21
  • The value you see from os tools is the memory given to the process by operating system. In this case it most likely close to -Xmx value. – Jayan Dec 27 '11 at 10:24
  • @Jayan actually, the app is run with -Xmx512... the whole app is using about 1.3 GB ... so the values are not close as far as I can tell. – AhHatem Dec 27 '11 at 11:01
  • @jelle I will try to use the tool to see what is it doing.. – AhHatem Dec 27 '11 at 11:02

2 Answers2

9

JVM memory usage can be explained by this image:

JVM Memory Usage

As you can see, it's not just -Xmx. Total process memory would also include the -XX:PermSize, stack size of all the threads, JVM memory used by the JIT and other internals. Don't forget about the memory mapped files which are also included in the process memory. IntelliJ IDEA uses memory mapped files for caches, so it can add several hundreds megabytes.

If you need the details, use some profiler like JConsole or YourKit.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • Thanks for the answer, I didn't know that the stack could be that big or that the mmap files could be in hundreds of megabytes... That show s why the difference is big... Although, it still seams weird to me the sizes here are a lot more than DotNet... – AhHatem Dec 28 '11 at 09:43
  • The image above is just an example, it's showing how many threads can be created on a 32-bit machine with 512K stack size and specified heap settings (1316 threads), normally the number of threads is much lower, however mapped files can indeed add a lot to the process memory. – CrazyCoder Dec 28 '11 at 13:20
1

It is worth remembering that Java allocates the maximum heap size on startup and this shows in the virtual memory size. (This is by default proportional to the amount of memory you have) This can be much larger than the actual main memory used.

I suspect you are looking at this virtual memory rather than the resident memory.

If you use pmap on linux you can see all the memory mapped regions and their sizes.

If a restart IntelliJ with an open project on Windows, it says its using 35 MB of about 100 MB used with a 494 M maximum. In task manager it says the size is 173 MB private and 196 MB total.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • The size 1300 MB I mentioned is the sum of the real physical memory + the swap value... Not the virtual size value which I know is almost useless. – AhHatem Dec 27 '11 at 11:00
  • What do you mean by "swap value"? The swap space used is usually global and is the memory allocated to programs which are not currently being used. – Peter Lawrey Dec 27 '11 at 11:12
  • If I open the detailed process information, I can see that this process is using about 1 GB of real memory and 300 MB of swap space (which is process specific, this is of course not the value of the whole swap) – AhHatem Dec 27 '11 at 11:16
  • Which OS are you using? Your process shouldn't be swapping at all. That certainly sounds strange. Can you capture the information you are getting and add it to the question? – Peter Lawrey Dec 27 '11 at 11:24
  • I am using Linux Kubuntu 11.10 32 Bit with sun java 6. There is something I don't get... The last couple of times the memory usage pattern was as I described and it remained that high...running IntelliJ with monitoring for Jconsole actually lowered the usage a lot, to about the half... that is about the heap + (less than 300 MB) which is normal and remained consistent with and without jconsole. On another hand, it seems to me that the GWT dev mode is consuming a lot of memory... I might have mistaken this with what the IDE is actually using.I will re-evaluate and post any meaningful results. – AhHatem Dec 27 '11 at 12:39
  • That all makes sense. If you can I would suggest you consider 64-bit OS with Java 6. There is very little downside and it can make more efficient use of virtual memory. – Peter Lawrey Dec 27 '11 at 12:54