-
Notifications
You must be signed in to change notification settings - Fork 56
/
GCTest.java
36 lines (36 loc) · 1 KB
/
GCTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ydk.test;
import ydk.lang.IO;
public class GCTest {
private String[] strings = null;
private int cnt = 0;
private static final int MAX = 2000;
public static void produceGarbage(){
for(int i=0;i<1000;i++){ new Object(); }
}
public static void produceArrayGarbage(){
for(int i=0;i<1000;i++) { Object[] unused = new Object[100]; }
}
public void fullGC(){
for(int i=0;i<MAX;i++){ new Object(); }
}
public void halfGC(){
strings = new String[MAX/2];
for(int i=0;i<MAX;i++)
if(i%2==0)
strings[cnt++] = "This is "+ i +" times to say hello to you\n";
cnt=0;
}
public void print(){
for(int i=0;i<MAX/2;i++){ IO.print(strings[i]); }
}
public static void main(String[] args){
produceGarbage();
produceArrayGarbage();
GCTest test = new GCTest();
test.fullGC();
test.fullGC();
test.halfGC();
test.halfGC();
test.print();
}
}