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 :


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)

Class diagram

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

To top of page