Memory issues with XML-based spring configuration

62 views Asked by At

I am creating a project for that I have tested both the XML-based spring configurations and Pure Java based configuration. My project is simple, it will listen on a RabbitMQ queue and perform an operation. Till now, I was not published anything in that queue. The code and requirement with both type of configurations are same. But, in case of XML-based configuration my memory uses are increases gradually and after sometime it will release all the increased memory. After that it again gradually increases.

The below JProfiler image that showing this scenario.

JProfiler image

Can someone explain why this happens? Is there something wrong with XML-based configuration? Thanks for your efforts.

edit 1: Spring version -> 5.1.6.RELEASE (For annotation based) and 5.2.18.RELEASE (For XML based)

edit 2: Code I have used,

<beans ....>
     <bean id="output" class="com.test.Output" />
</beans>

public class XmlConfigTest{
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("config/applicationContext.xml");
        Output output = (Output) ctx.getBean("output");
        output.performOperation();
    }
}


public class AnnotationConfigTest {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringContextGenerator.class);
        Output output = (Output) ctx.getBean("output");
        output.performOperation();
    }
}

I have used code like that where I get bean from XML and Annotations and perform a operations in it.

When it started:

JProfile Image

Just before GC collects all garbage object:

JProfiler Image

1

There are 1 answers

0
Grim On

That is totally fine and normal java Garbage-Collection behavior (as you can read here).

In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector.

Also, 70 MB is no huge memory allocation nowadays.