• Post Reply Bookmark Topic Watch Topic
  • New Topic

memory restriction  RSS feed

 
Sue Meng
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you restrict your java application to only use at most 128
megabytes of memory
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's JVMs use a fixed-sized heap (or at least, a heap that will grow only to a predetermined maximum size.) The default is 64MB for most releases. The total process size is bigger than that because that's only the heap available for Java objects, about 80MB total. The -mxNNm command-line switch sets the max heap size to NN megabytes. To limit to 128MB total RAM, something like -mx110m would do it.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
To limit to 128MB total RAM, something like -mx110m would do it.


I'd expect that to use more than 128MB in total. But that depends on a lot of factors, for example:

How big is the byte code of the program? That influences how big the permanent generation becomes, which resides outside the regular heap.

How many threads are started by the program? Every thread gets its own stack, which of course uses memory.

On which platform runs the program? That influences how big each thread's stack might become.

In the end, you will need to do some experimentation with your specific application, on the platform you are interested in.

If you are using a Java 5 runtime environment, you should use the jconsole application to get a view on how much memory is used for what.
 
Sue Meng
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys. I beleive tread stacktrace is the factor that may afect the use of memory.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!