Search code examples
javaspringresttemplate

Out of memory exception - perm gen space when creating rest template


I am creating a rest template RestTemplate restTemplate = new RestTemplate(). But I am getting this error out of memory exception during the creation. When I debug the rest template creation, the error exactly is occuring at MappingJackson2HttpMessageConvertor It is a multi threaded environment, still only one thread is creating the template, rest other threads are doing some other process.


Solution

  • OOM error is not about thread(stack) memory but about heap memory.

    It looks like you have too many objects in memory - make a heap dump to analyze what exactly fills all the memory: useful link about capturing heap dumps

    After an analysis of your specific case, as a solution (if it's okay to have such amount of objects in the memory) you may need to increase heap size via jvm parameter: -XX:MaxPermSize=512m