Spring Boot OutOfMemoryError
Spring Boot applications throw java.lang.OutOfMemoryError with different messages depending on which memory area is exhausted. Each requires a different fix.
Java Heap Space
The most common OOM. The heap is full of live objects:
# Increase heap
java -Xmx1g -Xms512m -jar app.jarBut increasing heap is a band-aid. Find the leak:
# application.yml — enable heap dump on OOM
JAVA_OPTS: >-
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/tmp/heapdump.hprofMetaspace
OutOfMemoryError: Metaspace means too many classes are loaded, often from reflection-heavy libraries:
java -XX:MaxMetaspaceSize=256m -jar app.jarThread Stack
Too many threads exhaust native memory:
# Reduce thread stack size (default 1MB)
java -Xss512k -jar app.jarAlso configure Tomcat's thread pool:
server:
tomcat:
threads:
max: 100 # Down from default 200Container-Aware JVM Settings
ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+HeapDumpOnOutOfMemoryError"
CMD java $JAVA_OPTS -jar app.jarConnection Pool Sizing
spring:
datasource:
hikari:
maximum-pool-size: 10
minimum-idle: 5Each connection uses memory for buffers and result sets.
Bugsly captures OutOfMemoryError events with the specific memory area, thread dump, and recent request context, dramatically reducing investigation time.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix CORS Blocked Error in Lang
Learn how to fix the CORS Blocked error in Lang. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read morePython Application Deployment Checklist
A thorough Python deployment checklist covering virtual environments, WSGI/ASGI servers, dependency pinning, and production configuration.
Read moreFix Content Security Policy Violation Error in React
Learn how to fix the Content Security Policy Violation error in React. Step-by-step guide with code examples and solutions.
Read moreHow to Fix Validationerror in NestJS In Production
A practical guide to resolving Validationerror in NestJS in production, with real code examples and debugging tips.
Read more