OutOfMemoryError
What is OutOfMemoryError?
OutOfMemoryError: The application tried to allocate more memory (heap space) than the system has available. An out-of-memory error means the program tried to use more memory than it is allowed. In Java it is OutOfMemoryError; in PHP the message is "Allowed memory size exhausted". In containers, the system may simply kill the process, which Kubernetes reports as OOMKilled.
Frequently asked questions about OutOfMemoryError
How is OutOfMemoryError used in practice?
The usual cause is loading too much data at once: an entire table into an array, a huge file into a string, or an image far larger than needed. Memory leaks in long-running processes, such as queue workers, are the other common cause.
What should you keep in mind with OutOfMemoryError?
Raising the limit sometimes helps, but often just delays the problem. Process data in chunks, stream files instead of reading them whole, and restart long-running workers regularly. For exports and imports, Laravel's chunk(), lazy() and streamed responses keep memory use flat no matter how big the data gets.
At a glance
| Category | Error types |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |