• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can i limit memory consumed by an Objects (Aplication)  RSS feed

 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

Is it possible to restrict an application to use limited number of memory say for example 50MB.Application should not uses more than that.

Is there anyway to put such kind of limitation?..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple way is to restrict the amount of memory available to the JVM. The option -Xmx defines the maximum amount of memory you want your allow your application. Set it to -Xmx50m and you application wont use more (though it may throw OutOfMemoryErrors if it needs more)
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That only limits the amount of virtual memory available to the Java heap. The JVM uses additional memory for its own code, loaded classes, stacks, various OS-specific resources, stuff I don't know about etc. If you have a 50MB heap, you might typically be using 70-80MB of virtual memory in total.

There's no simple way to limit the total virtual memory used by Java. Neither is there any way that I know to control the amount of physical memory used.

Final point: if you are using Windows, the Task Manager's default "Memory Usage" column shows physical memory usage. This is typically not very useful, and you should change your Task Manager options so it shows "VM Size" as well or instead.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!