Catching out of memory error in java
Catching out of memory error in java
You can catch it as it descends from Throwable:
try { // create lots of objects here and stash them somewhere } catch (OutOfMemoryError E) { // release some (all) of the above objects }