Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there are no OutOfMemoryError subclasses?

As we all know, there are multiple reasons of OutOfMEmoryError (see first answer). Why there is only one exception covering all these cases instead of multiple fine-grained ones inheriting from OutOfMEmoryError?

UML

like image 808
Tomasz Nurkiewicz Avatar asked Jun 05 '11 16:06

Tomasz Nurkiewicz


2 Answers

I'd expect because you really can't do anything else when that happens: it almost doesn't matter WHY you ran out, since you're screwed regardless. Perhaps the additional info would be nice, but...

I know tomcat tries to do this "Out Of Memory Parachute" thing, where they hold onto a chunk of memory and try and release it, but I'm not sure how well it works.

like image 77
Femi Avatar answered Sep 25 '22 02:09

Femi


The garbage collection process is deliberately very vaguely described to allow the greatest possible freedom for the JVM-implementors.

Hence the classes you mention are not provided in the API, but only in the implementation.

If you relied on them, your program would crash if running on a JVM without these vendor-specific sub-classes, so you don't do that.

like image 42
Thorbjørn Ravn Andersen Avatar answered Sep 23 '22 02:09

Thorbjørn Ravn Andersen