Is the memory immediately freed after executing pgm in one JVM ?
posted 12 years ago
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
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.