垃圾回收

This commit is contained in:
seahi 2024-11-10 22:11:57 +08:00
parent 886c549976
commit a6c121d9a1
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,28 @@
package chapter5;
class Person implements AutoCloseable {
String name;
public Person(String name) {
this.name = name;
}
public void close() {
System.out.println( name + " 要被回收啦!");
}
}
public class Example13 {
public static void main(String[] args) {
Person p1 = new Person("小明");
Person p2 = new Person("大王");
p1 = null;
p2 = null;
System.gc();
for (int i = 0; i < 1000000; i ++) {
// 为了延长程序运行的时间
}
}
}

View File

@ -0,0 +1,4 @@
package chapter5;
public class Example14 {
}