adjusting heap to combat OutOfMemory

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?
zacbellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sciuriwareCommented:
I think it means that suddenly "something" asks for at least 512-72 Mb more.
;JOOP!
0
TimYatesCommented:
have you tried:

-vmargs -Xmx512m

?
0
OptivoTomCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

zacbellAuthor Commented:
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
sciuriwareCommented:
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
OptivoTomCommented:
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
zacbellAuthor Commented:
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
sciuriwareCommented:
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
sudhakar_koundinyaCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.