Created
August 21, 2019 21:29
-
-
Save aghosn/1ddee4b0c9843c4a6c647c38ff93c4e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package a; | |
import java.util.Vector; | |
public class Main { | |
public static void main(String[] args) { | |
try { | |
Vector<Object> v = new Vector<Object>(); | |
while(true) { | |
byte b[] = new byte[1048576]; | |
v.add(b); | |
} | |
} catch (OutOfMemoryError e) { | |
e.printStackTrace(); | |
System.out.println("We caught the exception!"); | |
} | |
System.out.println("And we survived!"); | |
} | |
} | |
/* | |
Java output: | |
~> java a.Main | |
java.lang.OutOfMemoryError: Java heap space | |
at a.Main.main(Main.java:10) | |
We caught the exception! | |
And we survived! | |
native-image output: | |
~> ./a.main | |
Exception in thread "main" java.lang.OutOfMemoryError: Garbage-collected heap size exceeded. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment