Explain the reason of Out of Memory exception in Java.- The OutOfMemoryException can occur either the JVM may have a limit of memory to access to, or the system may have run out of physical memory or the application might consume too much memory space.
- To avoid these situations to occur, the applications need to be rewritten or reconfigure the heap by increasing the size for JVM.
- Other causes for this exception are as follows:
1. Spikes in usage/data volume:
- An application may be developed to handle a few amount of users or data but suddenly the volume of data or the users may increase and that time this trigger may function java.lang.OutOfMemoryError: Java heap space error.
2. Memory leaks:
- More memory will be consumed due to some programming errors. The leaking functionality of the application used will leave some of the objects in the heap space.
- With time this space is consumed and will trigger java.lang.OutOfMemoryError: Java heap space error.