Article DetailsDetailsHelp DetailsThe java.lang.OutOfMemoryError is an exception in Java that occurs when the Java Virtual Machine (JVM) cannot allocate enough memory for an object or operation. This error typically indicates a memory management issue that requires attention. Common Causes Insufficient Java Heap Space The error is most commonly caused by insufficient space in the Java heap.The garbage collector fails to free up enough memory for new object allocation, and the heap cannot expand further. Insufficient Native Memory This error can also occur when the JVM cannot access enough native memory to load a Java class. Excessive Garbage Collection Time In rare cases, the error may arise if excessive time is spent on garbage collection with little memory being freed. Native Library Limitations Native library code can throw this exception if a native memory allocation fails (e.g., when swap space is low). Behavior When the java.lang.OutOfMemoryError is triggered, a stack trace is printed, providing details about the location and circumstances of the failure.If the process is not terminated, the application may become unresponsive due to insufficient memory to perform further operations. Error Stacktrace in Neo4j Debug.log Caused by: java.lang.OutOfMemoryError at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?] at java.lang.reflect.Constructor.newInstance(Constructor.java:481) ~[?:?] at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:564) ~[?:?] at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:591) ~[?:?] at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:689) ~[?:?] at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159) ~[?:?] at java.util.stream.ForEachOps$ForEachOp$OfLong.evaluateParallel(ForEachOps.java:209) ~[?:?] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[?:?] at java.util.stream.LongPipeline.forEach(LongPipeline.java:445) ~[?:?] at org.neo4j.gds.similarity.nodesim.NodeSimilarity.lambda$computeTopKMapParallel$11(NodeSimilarity.java:366) ~[neo4j-graph-data-science-2.6.7.jar:?] at org.neo4j.gds.core.concurrency.ParallelUtil.lambda$parallelStreamConsume$1(ParallelUtil.java:98) ~[neo4j-graph-data-science-2.6.7.jar:?] at org.neo4j.gds.core.concurrency.ParallelUtil.lambda$parallelStream$0(ParallelUtil.java:75) ~[neo4j-graph-data-science-2.6.7.jar:?] at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1428) ~[?:?] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] Caused by: java.lang.OutOfMemoryError: Java heap space Steps to Resolve the Issue Increase Java Heap Size for Neo4j by configuring server.memory.heap.initial_size and server.memory.heap.max_size See here for more details on Memory Configuration Optimize Memory Usage Identify and address memory leaks or excessive object creation in the application code.Use tools like JProfiler, VisualVM, or Eclipse MAT to analyze heap dumps. See this article for analyzing a java heap dump Monitor Native Memory Check system-level memory usage to ensure adequate native memory and swap space.On Linux/Unix, use commands like free -h or top to monitor memory. Configure Exit on OutOfMemoryError in Neo4j.conf Add the following JVM option to the configuration file to terminate the process immediately when an OutOfMemoryError occurs: dbms.jvm.additional=-XX:+ExitOnOutOfMemoryError This ensures the process does not remain in an unstable or unresponsive state and facilitates faster recovery or restart. Kill Unresponsive Processes If the Neo4j becomes unresponsive and does not terminate on its own, manually kill the process.Identify the process ID (PID) using the following command: ps -eaf | grep neo4j Terminate the process using the kill command: kill -9 <pid> Replace <pid> with the actual process ID of the unresponsive Neo4j application. See this article for recovery upon Out Of Memory ErrorInformationTitleHow to handle OutOfMemoryError:Java heap spaceArticle Created Date11/27/2024, 8:29 AMURL NameHow-to-handle-OutOfMemoryError-Java-heap-spaceLast Modified Date3/13/2025, 11:54 AM