हाँ, यह आसान
public class X {
protected void finalize() {
while (true) {
}
}
public static void main(String[] args) throws Exception {
while (true) {
new X();
}
}
}
कुछ समय मैं
मिला के बाद परीक्षण करने के लिए होगा विभिन्न मामलों में जहां को अंतिम रूप देने विधि जीसी की गारंटी नहीं है मिल जाएगा
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
जब मैंने अंतिम रूप दिया() परीक्षण कभी नहीं रुक गया। ध्यान दें कि यह कुछ समय लगता है इससे पहले कि JVM OOM चला जाता है
BTW यह इस परीक्षण
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();
}
}
}
जीसी बाहर तोड़
Exception in thread "main"
java.lang.OutOfMemoryError: Java heap space
at test.X.<init>(X.java:5)
at test.X.main(X.java:13)
टिप्पणी //System.out.println चलाने के लिए पर्याप्त है (); और यह गैर-स्टॉप
स्रोत
2013-01-24 11:15:21
क्या आपको यह कोशिश करने से रोकता है? वास्तव में इसे आजमाने के लिए –