Re: Heap and Memory Footprint



parmindersk@xxxxxxxxx wrote:
I did that, but that doesn't help. I set the size to 64 megs. but the
VM size behaved the same way. Please let me know if there's something
else that can be done.


Also, can you please point me to the diff between the VM size and the
heap size?

One additional thing you might want to look out for. If you have any mixed language objects (i.e. Java objects which have underlying native memory associated), when the object is created memory is allocated in both the Java heap and the C native heap. The Java heap is controlled by the max heap size parameter, but the C memory is simply allocated using malloc (and causes the JVM to grow). Typically such objects have a manual tidy method (often close()), with a fallback of object finalisation. It is important to explicitly call close() - otherwise if the object gets promoted to the old area, the memory will not be freed until the object gets garbage collected from the old area which can take a very, very long time (and in the worst case you may have the process hit a memory limit without a garbage collection occurring as only the Java heap's behaviour will trigger garbage collection).

There are examples of such objects in the Java library (e.g. some of the InputStream and OutputStream classes), as well as many 3rd party libraries (e.g. I've seen it with database cursor implementations).

So in general, if a class has a close() type method, it must always be explicitly called, and in a finally block (so that exceptions don't cause leaked resources).

Cheers

Dave
On May 30, 4:53 pm, Joshua Cranmer <Pidgeo...@xxxxxxxxxxxxxxxx> wrote:

parminde...@xxxxxxxxx wrote:

I used JProf to see that my Swing app has 40 megs of heap allocated to
it. However, over time VM size of the java.exe process keeps on rising
and at times hits 300 megs. I understand that the JVM may be using
this memory for internal purposes. But is there a way to limit the
size to which the VM grows?

In short if I need to tell my customers that when they run my app the
VM size will not grow higher than some limit. Are there any VM
parameters I can use to ensure this.

From Sun's java command line reference (keep in mind: this is a
'non-standard' option, and is only guaranteed for Java versions ~ 1.1 - 6):

-Xmxn
Specify the maximum size, in bytes, of the memory allocation pool.
This value must a multiple of 1024 greater than 2MB. Append the letter k
or K to indicate kilobytes, or m or M to indicate megabytes.
(e.g. -Xmx40m)

This is the URL for the Java 6 version of the command line:http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#n...

and the earlier versions can be obtained by changing the javase/6/ to
j2se/1.{5,4.2,?}/



.



Relevant Pages

  • Re: OO compilers and efficiency
    ... >> Objects in Java are heap allocated, ... >> up stuff that's gone out of scope that in other languages would be ... Certainly, better garbage collection strategies can be used, like the ...
    (comp.programming)
  • Re: how to enlarger Java heap size?
    ... Is there a way to tell Java on the command line to take as much heap ... size as the physical memory or the virtual memory of the computer ... You could write a helper application that detects the installed physical memory and then passes that along as it starts the Java process. ...
    (comp.lang.java.programmer)
  • Re: PermGen, Garbage Collection and CPU utilization
    ... Memory and Java Heap Space. ... Learn what its upper and lower limit regions of usage are and allocate ...
    (comp.lang.java.programmer)
  • Re: Can you write code directly in CIL ???
    ... >>> I highly recommend that you read up on how Garbage Collection works ... > the execution time was still 1/10, but from the outside the execution time ... >> One thing that it can not do is to reclaim memory that is still in use. ... the GC heap would overrun the gen0 heap threshold. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: -Xmx out of memory errors
    ... The issue is maximum heap... ... or unbounded doesn't mean that java needs to sbrk that ... wouldn't mean that java by default sbrks the whole ... I think you mean memory allocated by malloc... ...
    (comp.lang.java.programmer)