Có nó sẽ, dễ dàng để kiểm tra
public class X {
protected void finalize() {
while (true) {
}
}
public static void main(String[] args) throws Exception {
while (true) {
new X();
}
}
}
sau một thời gian tôi đã
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
khi tôi xóa xong() thử nghiệm không bao giờ dừng lại. Lưu ý rằng phải mất một thời gian trước khi JVM đi oom
BTW đó là đủ để chạy thử nghiệm này
public class X {
byte[] a = new byte[100 * 1000 * 1000];
protected void finalize() {
System.out.println();
}
public static void main(String[] args) throws Exception {
while (true) {
new X();
}
}
}
để phá vỡ GC
Exception in thread "main"
java.lang.OutOfMemoryError: Java heap space
at test.X.<init>(X.java:5)
at test.X.main(X.java:13)
bình luận ra //System.out.println (); và nó hoạt động không ngừng
Nguồn
2013-01-24 11:15:21
Điều gì ngăn bạn không dùng thử? –