Tutorial Addendum on JVM - Anamnesis Administration
Overview
Generally, a new s/computers-and-technology/jvm-list/' onMouseOver="tip('infobox1')" onMouseOut="untip()"> JVM is using the afterward rules to administer memory:
- When a JVM is invoked to run an application, it will ask the operating arrangement
for abundant anamnesis to run the JVM itself and some chargeless anamnesis for the application
to make new objects.
- When a new item is created, the JVM will admeasure anamnesis for that item out
of the chargeless anamnesis area.
- When the chargeless anamnesis breadth is accepting too small, the JVM will ask the operating
system for more.
- When a item is no best acclimated by the application, it will be destroyed. Its
memory will be freed up and alloyed aback to the chargeless anamnesis area.
- When the chargeless anamnesis breadth is acclimated up, and there is no added added memory
available from the operating system, the JVM will stop the appliance and issue
the "Out of anamnesis error".
Out of Anamnesis Error
I wrote the afterward program to try to advance JVM for added anamnesis in a loop:
/**
* MemoryCrash.java
* Absorb (c) 2002 by Dr. Yang
*/
class MemoryCrash {
accessible changeless abandoned main(String[] a) {
int max = 100;
Runtime rt = Runtime.getRuntime();
Object[] arr = new Object[max];
for (int n=0; n<max; n++) {
System.out.println("Having "+n*10+" MB and abacus 10 MB...");
arr[n] = new long[10*1024*128];
System.out.println(" Chargeless memory: " + rt.freeMemory());
System.out.println("Total memory: " + rt.totalMemory());
try {
Thread.sleep(2*1000);
} bolt (InterruptedException e) {
System.out.println("Interreupted...");
}
}
}
}
Output on HotSpot Applicant VM with -Xms2m -Xmx64m
Having 0 MB and abacus 10 MB...
Chargeless memory: 1897344
Total memory: 12521472
Having 10 MB and abacus 10 MB...
Chargeless memory: 8463216
Total memory: 29573120
Having 20 MB and abacus 10 MB...
Chargeless memory: 6275936
Total memory: 37871616
Having 30 MB and abacus 10 MB...
Chargeless memory: 14644240
Total memory: 56725504
Having 40 MB and abacus 10 MB...
Chargeless memory: 4157184
Total memory: 56725504
Having 50 MB and abacus 10 MB...
Exception in cilia "main" java.lang.OutOfMemoryError
|
Tags: system, application, management, memory, adding, object memory, adding, system, object, println, application, , free memory, memory area, system out, jvm will, free memory area, memory area when, jvm memory management, |
Also see ...
PermalinkArticle In : Computers & Technology - jvm