1. "Java Programmer to work that thing" the author of the memory of the description of the array
2. Actual test situation:
/** * Test one-dimensional array memory/public static void Testonearray () {System.out.println ("Maximum memory for the current virtual machine:" + Runti
Me.getruntime (). MaxMemory ()/1024/1024 + "m------" + runtime.getruntime (). MaxMemory () + "byte"); System.out.println ("Pre-cycle virtual machine occupied memory:" + runtime.getruntime (). TotalMemory ()/1024/1024 + "m====" + runtime.getruntime ().
TotalMemory () + "byte");
try {int len = 1024 * 1024 * 300;//set cycle times byte[] buffer = new Byte[len];
for (int i = 0; i < len; i++) {Buffer[i] = (byte) i; System.out.println ("Pre-loop virtual machine occupied memory:" + runtime.getruntime (). TotalMemory ()/1024/1024 + "m====" + runtime.getr
Untime (). TotalMemory () + "byte");
catch (Error E) {System.out.println ("encountered errors:" + E);
* * * Test results: Maximum memory for current virtual machine: 793m------832438272byte cycle before virtual machine occupied memory: 127m====133234688byte
Virtual machine occupied memory before cycle: 427m====447877120byte */} /** * Test two-dimensional array memory/public static void Testtowarray () {System.out.println ("Maximum memory for the current virtual machine:" + Runtime
. GetRuntime (). MaxMemory ()/1024/1024 + "m------" + runtime.getruntime (). MaxMemory () + "byte"); System.out.println ("Pre-cycle virtual machine occupied memory:" + runtime.getruntime (). TotalMemory ()/1024/1024 + "m====" + runtime.getruntime ().
TotalMemory () + "byte");
try {int len = 1024 * 1024;//set cycle times byte[][] buffer = new BYTE[LEN][300];
for (int i = 0; i < len; i++) {buffer[i][0] = (byte) i;
BUFFER[I][1] = (byte) i; System.out.println ("Pre-loop virtual machine occupied memory:" + runtime.getruntime (). TotalMemory ()/1024/1024 + "m====" + runtime.getr
Untime (). TotalMemory () + "byte");
catch (Error E) {System.out.println ("encountered errors:" + E);
* * * Test results: Maximum memory for current virtual machine: 793m------832438272byte cycle before virtual machine occupied memory: 127m====133234688byte Virtual machine occupied memory before cycle: 398m====417398784byte */}
Analysis: The individual believes that the previous test did not directly output the following JVM memory used in the loop; compare my test, if use after the cycle of minus the cycle of memory to overthrow the predecessor of the theory, just the opposite, for which one is right, awaiting everyone's textual research.