Solved

adjusting heap to combat OutOfMemory

Posted on 2003-11-10
9
1,593 Views
Last Modified: 2013-11-23
I'm writing an application with huge memory requirements for WinXP (developing using JCreator Pro). I routinely get OutOfMemory errors when running this application and tried to adjust the heap sizes to avoid such errors. The following is the command line i use:

-Xms256m -Xmx512m

to set the initial and maximum heap sizes. When I run the application, the Windows Task Manager indicates that the application uses up to about 72 MB memory before I get the OutOfMemory error.

What am I doing wrong, since I want java to use up to 512 MB to run the application, and it only appears to use about 72MB before returning the OutOfMemory error?

Any thoughts?
0
Comment
Question by:zacbell
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 9720664
I think it means that suddenly "something" asks for at least 512-72 Mb more.
;JOOP!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9720669
have you tried:

-vmargs -Xmx512m

?
0
 

Accepted Solution

by:
OptivoTom earned 75 total points
ID: 9723828
First of all (from my experience) the Task Manager does not correctyl display memory usage after the garbage collection starts to collect objects for the first time... espacilly if the garbage collector has to run heavily (because you are running out of memory). Try to add columns to the display of the task manager which display virtual memory, max. memory etc. to get a better picture of what you system is doing. Most of the time windows starts to swap heavily and thereby suggesting (by the task manager) it only uses a fraction of the available memory. If you experience a dramatic (erratic) change of memory usage (lets say jumping from 72 to 500 and back to 120 in just a  couple of seconds) it is a clear indication that the garbage collector is freeing memory which the VM is consuming instantly and as the system does not have the amount of required memory installed it swaps...

In sumary ... don't trust the taskmanager :-( Most certainly the VM really uses all the memory and then just quits. You could counter that by increasing the initial and max heap size of your VM as you allready did... other than that more RAM would be an option ;-)

To really get to the source of the problem would be to profile your application as to how much memory is allocated to your object instances. Some good tools to start with would be:

jprofiler: http://www.jprofiler.com/

plugin for eclipse: http://jmechanic.sourceforge.net/

hope that helped...

Bye Tom
0
 

Author Comment

by:zacbell
ID: 9769635
Per Tom's suggestion, I installed an evaluation version of JProfiler. Here's what's interesting: when I run my program using JProfiler, it uses up to about 300 MB memory and successfully runs to completion. However, when I run the program directly using java.exe, it only uses about 75 MB of memory and fails with an OutOfMemory error. There's no indication from JProfiler that there is erratic memory usage (i.e. jumping from 50MB to 500MB) - just smooth memory growth as the program executes.

Here are the command line arguments for running with and without JProfiler:

C:\j2sdk1.4.2_02\bin\java.exe "-Xint" "-Xrunjprofiler:port=31769" "-Xbootcla
sspath/a:C:\Program Files\jprofiler\bin\agent.jar" "-classpath" "my path" "class_file"

C:\j2sdk1.4.2_02\bin\java.exe -classpath "my path" class_file -vmargs -Xms256m -Xmx512m

Any ideas why the occurance of a memory error depends on whether JProfiler is running or not? Or perhaps there's something else different between running with and without JProfiler?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 24

Expert Comment

by:sciuriware
ID: 9769646
I do hope it's not another bug in 1.4.2_02
Can you try to run it somewhere 1.4.1 or 1.4.2?
;JOOP!
0
 

Expert Comment

by:OptivoTom
ID: 9769757
What JProfiler does is: load itself and than invoke your main class. It might be possible, that it changes the settings for initial and maximum heap size but I doubt it. So what is a difference is, that by running your application "through" JProfiler you effectively ommit the arguments for inital and max heap.

Speaking of that... I would strongly recommend to set the inital heap size to either 1/4 of the max heapsize, the same as the max heap size or (best) not set it at all. Because setting the minimum heapsize prevents the JVM also from shrinking the heap as it would see fit.

My guess would be to ommit the -Xms setting and set the -Xmx setting to approcimately 1 1/2 of your physical memory.

Bye Tom
0
 

Author Comment

by:zacbell
ID: 9776508
I think I figured out the problem, although it turned out to be terribly unsatisfying. I found that I was specifying the heap size command line options after the class file, instead of before it - so Java had no idea I was specifying the heap size. Everything worked as expected when I put the options where they should have gone. Thanks for everyone's help - I do apologize that the problem was such a simple mistake.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 9776682
You're wrong: the simplest mistakes are the most important.
I just read that in 1995 a Peruvian airplane went down because of a piece of adhesive tape
on a control.
And we all learn from this question too!
;JOOP!
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 10232789
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[paq'ed and points refunded]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java virtual machine monitoring tools 3 40
countX 22 70
noX challenge 17 77
wordcount challenge 11 78
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now