Continuing in this troubleshooting series of simulating and troubleshooting performance problems in Kotlin, let’s now discuss how to simulate the java.lang.OutOfMemoryError: Java Heap space problem. java.lang.OutOfMemoryError: Java Heap space will be thrown by the application when it generates more objects than the maximum configured heap size.
Kotlin OutOfMemoryError Program
Here is a sample Kotlin program, which generates the java.lang.OutOfMemoryError: Java Heap space problem.