Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created August 18, 2019 04:44
Show Gist options
  • Save ashkrit/3e721ef22c01a126bdf26386d4e01c1f to your computer and use it in GitHub Desktop.
Save ashkrit/3e721ef22c01a126bdf26386d4e01c1f to your computer and use it in GitHub Desktop.
public class MemoryAllocator {
public static final int KB = 1024;
static int mbToAllocate = Integer.getInteger("mb", 1000);
public static void main(String[] args) {
System.out.println(String.format("Start allocation of %s MBs", mbToAllocate));
for (var i = 0; i < mbToAllocate; i++) {
var garbage = new byte[KB * KB];
}
System.out.println("I was Alive after allocation");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment