aspose file tools*
The moose likes Java in General and the fly likes Heap memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Heap memory" Watch "Heap memory" New topic
Author

Heap memory

sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 104
Hi Folks,
Iam working on memory profiling of the application.

I've couple of doubts regarding heap memory.

1. What is heap memory, how is it different from main memory.
2. Is there any limitation for JVM to allocate the main memory as I've seen this problem that the application is failed to work after it allocates certain memory.

Any help would be appreciated.

Thanks,
Sam
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by sammaiah kyatham:
Hi Folks,
Iam working on memory profiling of the application.

I've couple of doubts regarding heap memory.

1. What is heap memory, how is it different from main memory.
2. Is there any limitation for JVM to allocate the main memory as I've seen this problem that the application is failed to work after it allocates certain memory.

Any help would be appreciated.

Thanks,
Sam


The heap memory cannot be changes once the JVM starts up and then if there is any memory shortage then you will get out of memory error.
You can increase the heap size before the jvm starts up , if you do not set the it takes the default.I think that is implementation specific.
It might set the max size of the heap to 1/4 of the total available memory at the time of jvm start up.


Rahul Bhattacharjee
LinkedIn - Blog
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

Not sure what you mean by 'main' memory.

in a program, we generally refer to two kinds of memory - the stack, and the heap. each time a new method is called, it gets added to the stack. the topmost method is the one that is currently executing. when the method exits, it gets popped of, and you drop back into the calling method.

The heap is where objects get created. objects come and go from just about any part of the heap - it will not be filled in one contiguous block. Heap memory is what needs to get GC'd. the stack memory clean itself up by definition.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Rahul Bhattacharjee:
The heap memory cannot be changes once the JVM starts up


That's not really true.

You cannot change the heap settings (the -Xwhatever parameters), once the JVM has started. But you can choose settings that allow the heap size to vary widely during the lifetime of the JVM.

You can set initial and maximum sizes for the heap with -Xms and -Xmx. The JVM will automatically vary the heap size between these limits, as your application demands more or less heap, during its run. You can adjust exactly when it grows and shrinks the heap using the -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio settings. Read the Sun documentation for more on this.
[ March 23, 2007: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Fred Rosenberger:
Not sure what you mean by 'main' memory.


By main memory I mean the total physical memory.
sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 104
Yes Rahul. Main memory here is nothing but Physical memory.

Iam running the application using below java options.

java -Xms140m -Xmx200m -jar application.jar

I tried to run the application with differet values of -Xms and -Xmx but I didn't see any difference. Still I'm able to see memory problem.

Total physical memory(RAM) in my system is 512MB. I don't have any problem if JVM takes more than 300MB but JVM not allocating.

Here my question is, why JVM not able to allocate more memory even though it is available in system.

Do I need to specify anything else to allocate more memory other than above options.

Any suggestions.. welcome pls.

Thanks,
Sam
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
At first glance, that command line looks OK. I don't really see why you need to specify such a large value for -Xms; normally one specifies a smallish value or no value, and lets the JVM choose. It's only -Xmx that one normally wants to play with.

One thing occurs to me. If you are using Windows and you are looking at memory usage in Windows Task Manager, you must use the "VM Size" column, NOT the "Memory Usage" column. The "Memory Usage" column tells you how much physical memory is used by the process; that's not what -Xmx controls and is under the control of the OS, not you. The "VM Size" tells you how much virtual memory is allocated to the process; that is what -Xmx controls.

The "VM Size" column is not shown by default. You must add it (and remove "Memory Usage"?) from the View menu of Windows Task Manager.

This is not a nit-picky difference - if you're looking at "Memory Usage", that figure is of almost no relevance at all.
[ March 23, 2007: Message edited by: Peter Chase ]
sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 104
Thanks Peter,
Now I understood.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Heap memory