• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why make process size so huge on WindowsXP?  RSS feed

 
Joseph Goodman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like no matter how much memory my application uses, the JRE process is several times larger. For example I can make a very simple app that just shows a JFrame. Runtime.getRuntime.totalMemory() claims that I am using 4MB, which seems like a lot for a simple frame window. TaskManager says that the application (JRE) is using 18MB. The JVM process size is over 4X larger. Is there anything that the developer can do to reduce the process size?

I realize that the JRE is loading classes, spawning its own threads which require heap space and stack space, but the perception that most people get when looking at TaskManager is "Wow there must be a memory leak in that application it using 80MB." I know because my manager has said some close to that with a few expletives thrown in. This makes it hard for me to convince him that Java is a great choice for developing desktop applications.

I think that instead of implementing new language features like auto-boxing and spending time developing Timbuktu language support, this needs to be addressed. Otherwise I think many desktop application developers will have the same difficulty and may forced to look at using C++ with GTK or Mono.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Windows task manager can display "Mem Usage" or "VM Size". The latter is more helpful, as it tells you how much virtual memory is used by Java.

Java does use quite a lot of (virtual) memory, even for small programs. However, your application may be able to use less.

Some of the memory used by your Java application is for the Java heap. Because Java is garbage-collected, the amount of memory for the heap must be bigger than the actual amount of memory used by live objects on the heap. In general, the more "spare" heap there is, the faster your Java will run.

If you are sensitive to memory usage, and your application does not actually need huge amounts of heap for live objects, you may want to reduce the initial and/or maximum heap sizes. There are command-line switches for this when invoking Java such as "-Xmx" and "-Xms".

A lot of the memory used by Java is for loaded classes. Some reduction in memory use might be possible, by avoiding using classes that you don't need. Classes on the classpath don't use memory, unless they are actually loaded (i.e. used within your source code or the JDK itself), BTW.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Decreasing mem-size will get of lower interest every year. Working on that is allmost time-waste.

And I guess, you can use the switches, Peter mentions, if it's a real problem.
 
Joseph Goodman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I strongly disagree Stefan. I know memory is getting cheaper and more abundant but being conservative with memory should be important. What if all desktop applications had the attitude "its just RAM, no need to deallocate". RAM would become scarce! Our desktop application has to run on the same desktop as other Java apps.

Here is a good example of what I am talking about:
Notepad.exe uses 2.6 MB under TaskManager
The Notepad example that comes with jdk1.5 uses 19.1 MB according to TaskManager.

Why?!

The Notepad example really doesn't do much. When you make a more complex desktop application like NetBeans or Eclipse, you can be using 67 MB of RAM. C++ desktop applications seem to use much less memory. This coupled with the "Java is slow" myth makes IT managers think twice before developing desktop applications with Java.

Don't get me wrong, I am a advocate of Java. It is an elegant and powerful language. It is also very portable, which is why we chose it in the first place. I just wish Sun would fix this problem or at least explain it so that the Java haters of the world would have one less excuse.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well. 20 MB for some kind of notepad is 20 MB to much.
70 MB for eclipse isn't too much - compare it to similar IDEs.

If you run multiple java-apps simultanously, you could try to save RAM by using the same jvm, I guess.
If I start the same application 3 times, started by one jvm, I get the same amount of RAM used, like starting it once.

Opening some native GUI applications in linux doesn't seem to be very cheap too.
SciTE: 12 MB, kate 22 MB, both are editors with syntax-highlightening and multi-file support.

In real live I don't have problems with running java applications (and I never heared from users, having them), using 256 MB real RAM and 1 GB swap.

I don't know, how to interpret the task-manager output, and I'm not sure, how to interpret the top output on linux expertly, but I guess the critical value is the 'resident'-value, not the 'shared'.
And perhaps Josephs Manager isn't that expert too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!