Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Machine > Re: Heap and Me...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 7 Topic 773 of 803
Post > Topic >>

Re: Heap and Memory Footprint

by David Gourley <dave@[EMAIL PROTECTED] > Jun 4, 2007 at 08:32 PM

parmindersk@[EMAIL PROTECTED]
 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...@[EMAIL PROTECTED]
> wrote:
> 
>>parminde...@[EMAIL PROTECTED]
 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,?}/
> 
> 
>




 7 Posts in Topic:
Heap and Memory Footprint
"parmindersk@[EMAIL   2007-05-30 12:22:26 
Re: Heap and Memory Footprint
Joshua Cranmer <Pidgeo  2007-05-30 20:53:25 
Re: Heap and Memory Footprint
"parmindersk@[EMAIL   2007-05-31 11:51:16 
Re: Heap and Memory Footprint
David Gourley <dave@[E  2007-06-04 20:32:00 
Re: Heap and Memory Footprint
hbdere <hbdere@[EMAIL   2007-06-01 23:20:51 
Re: Heap and Memory Footprint
"parmindersk@[EMAIL   2007-06-08 20:09:49 
Re: Heap and Memory Footprint
David Gourley <dave@[E  2007-06-11 22:05:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 0:58:29 CDT 2008.