Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

freeing memory of JVM  RSS feed

 
Steve Mutanson
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a batch file doing the following thing ---
************
java MyApp arg_1
java MyApp arg_2
...
...
java MyApp arg_99
java MyApp arg_100
*************
I found the speed was fast in the beginning but it significantly slows down when it reaches "java MyApp arg_80". SInce each "java MyApp. . .." invokes a new JVM, I suspect that when the batch file reaches "java MyApp arg_80" some previously created JVM have NOT been really cleaned up in the memory yet, i.e. some of the previously created JVM are still occupying the memory space so the memory is gradually occupied fully, and this causes the slowing down of the newly created JVM.
Does this make sense ? I am not sure. Theoretically when a "java MyApp arg_n" is done, the OS should free the memory it occupies, right ? So, does what I said in last paragraph make sense ?
Thanks,
steve
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The only solution to this kind of scenario depends on
One solution would be enhancing the RAM and calling GC would not be of much help because there is no guarantee that GC would get invoked when u call it. I read some where that we can edit some parameters for GC so when and object is called a specified "n" # of times GC kicks in and performs the clean up. Try to grab some article on GC. It should help you.

Cheers,
Gaya3
---------------------------------
Prasanna Kumar R.v
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way you can design the program so it can run your programs as threads within 1 JVM? This would consume far less memory than loading 100 JVMs. You could either pass your args like:
java MyClass arg1, arg2
or read the input from a file
java MyClass myfile.dat
steve - http://www.jamonapi.com
 
Steve Yu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I will consider modifying the code. But I still want to confirm this ---
After the system finishes executing "java MyApp arg_n" and starts moving to the next "java MyApp arg_n+1", since the first pgm is done, will the system immediately free its memory or not ?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gayathri Prasad:
One solution would be enhancing the RAM and calling GC would not be of much help because there is no guarantee that GC would get invoked when u call it.

GC'ing doesn't give back memory to the OS.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Mutanson:
Does this make sense ? I am not sure. Theoretically when a "java MyApp arg_n" is done, the OS should free the memory it occupies, right ? So, does what I said in last paragraph make sense ?

I am not sure.
I get it that you are using Windows? Take a look at the middle tab of the Taskmanager (processes?). There you should be able to see which processes are eating up your memory.
 
Joakim Bissmark
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that his has nothing to do with GC, which
takes place inside an executing java process. Here
we start a number of separate java processes, each
with its own GC thread.
This is a matter of how long each Java process executes,
how much memory each process uses,
and how the OS handles that memory. Probably java processes
n-1, n-2,... have not finished execution before process n
starts. If there are several processes executing at the
same time and they each use quite a lot of memory, of
course the OS will have a hard time. It will probabaly
swap pages to disk which makes everything slower.
I would add a println() with a unique identifier at the
first and last line in the main method to see if there
are several processes executing at the same time.
Joakim
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!