Yes it will, easy to test
public class X {
protected void finalize() {
while (true) {
}
}
public static void main(String[] args) throws Exception {
while (true) {
new X();
}
}
}
after some time I got
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
when I removed finalize() the test never stopped. Note that it takes a while before JVM goes OOM
BTW it's enough to run this test
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();
}
}
}
to break 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)
comment out //System.out.println(); and it works non-stop