Java : OutOfMemoryError con ejemplos
OutOfMemoryError (Java SE 23 & JDK 23) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos OutOfMemoryError.
Nota :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
Se lanza cuando la Máquina Virtual Java no puede asignar un objeto por falta de memoria y el recolector de elementos no utilizados no puede liberar más memoria. La máquina virtual puede construir objetos OutOfMemoryError como si la supresión estuviera deshabilitada o el seguimiento de la pila no fuera escribible. (Traducción automática)
try {
final var array = new int[1000000000];
} catch (OutOfMemoryError e) {
System.out.println(e);
}
// Result
// ↓
//java.lang.OutOfMemoryError: Java heap space
Constructors
OutOfMemoryError ()
Construye un OutOfMemoryError sin mensaje detallado. (Traducción automática)
final var e = new OutOfMemoryError();
System.out.println(e); // java.lang.OutOfMemoryError
OutOfMemoryError (String s)
Construye un OutOfMemoryError con el mensaje de detalle especificado. (Traducción automática)
final var e = new OutOfMemoryError("abcd");
System.out.println(e); // java.lang.OutOfMemoryError: abcd
System.out.println(e.getMessage()); // abcd
Methods declared in Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
Consulte el siguiente enlace.
Related posts
- Ejemplos de API
- Error
- Exception
- RuntimeException
- ArrayIndexOutOfBoundsException
- BufferOverflowException
- BufferUnderflowException
- DateTimeException
- DateTimeParseException
- IllegalArgumentException
- IllegalStateException
- IndexOutOfBoundsException
- NoSuchElementException
- NullPointerException
- PatternSyntaxException
- ReadOnlyBufferException
- StringIndexOutOfBoundsException
- Throwable