It's not a secret anymore!*
The moose likes Java in General and the fly likes Is the memory immediately freed after executing pgm in one JVM ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is the memory immediately freed after executing pgm in one JVM ?" Watch "Is the memory immediately freed after executing pgm in one JVM ?" New topic
Author

Is the memory immediately freed after executing pgm in one JVM ?

Steve Mutanson
Ranch Hand

Joined: Apr 15, 2003
Posts: 67
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
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

The memory allocated by a JVM does exist at the operating system level for some time after the JVM terminates. The OS has to notice that the program has terminated, then it takes some time to free what has been allocated (i.e. swap space or virtual memory, RAM, file descriptors, sockets and so on). In your situation it sounds like you don't have enough RAM in your computer to keep up with all the processes and your OS is bogging down cleaning up old processes and allocating resources for the new processes. You can monitor your system's resource allocation with tools like System Monitor and Task Manager in Windows NT-XP-2000 or 'ps' or 'top' on a Unix system.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
 
subject: Is the memory immediately freed after executing pgm in one JVM ?
 
Similar Threads
Doubt in K&B Self Test from Last Chapter
NX: Primary Key and Immutable Key
Memor Leak
freeing memory of JVM
Memory Profiling Tomcat Running as Service