Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:18:53+00:00 2026-06-08T08:18:53+00:00

As I noticed crazy high RAM usage on my client application (Swing-based), I started

  • 0

As I noticed crazy high RAM usage on my client application (Swing-based), I started looking into it and it seems like this is somehow related to Annotation-based configuration in Spring. As you will see in my edits below, i realized that this occurs only on 64-Bit JVM.

See the following testcode:

xml-based configuration

<beans ....>
     <bean id="xmlConfigTest" class="at.test.XmlConfigTest" />
</beans>

public class XmlConfigTest extends JFrame {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("config/applicationContext.xml");
        XmlConfigTest frame = (XmlConfigTest) ctx.getBean("xmlConfigTest");
        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Uses up about 32MB memory, which seems ok to me.

Now the same with annotation based configuration:

@Service
public class AnnotationConfigTestFrame extends JFrame {
    public static void main(String[] args) throws InterruptedException {
        ApplicationContext ctx = new AnnotationConfigApplicationContext("at.test");

        AnnotationConfigTestFrame frame = (AnnotationConfigTestFrame) ctx
            .getBean("annotationConfigTestFrame");
       frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
       frame.setVisible(true);
    }
}

Not only takes it noticeable longer to open the frame, but the memory consumption sky-rockets to 160MB memory on startup and then levels off at about 152MB, which seems really high to me. And remember, this is only the most basic case, the client application i develope atm eats up over 400MB already, which is just too much for older machines.

Does anyone have an explanation for this behaviour? I don’t understand..

(Using 3.1.1.RELEASE here btw.)

edit*
As suggested by axtavt, i also tried to construct the AnnotationConfigApplicationContext directly with the Test-Class as Argument, so that no classpath-scan is necessary. Didn’t changed anything about the memory consumption unfortunately.

edit 2 removed, see edit 3

edit 3
I now tested on the same machine (Windows 7 64-Bit) with both 32-Bit and 64-Bit JVM and the test-programms from above. This are the results:

xml based configuration:

32-Bit JVM: 16MB
64-Bit JVM: 31MB

annotation bassed configuration:

32-Bit JVM: 17MB
64-Bit JVM: 160MB

So on 32-Bit JVM both proramms are close, which is pretty much what i would expect. On 64-Bit though, this is different. Even the first programm uses twice as much memory on 64-Bit, which already seems to be too much. Still it’s nothing against the second program, which uses nearly 10 times more memory on 64-Bit.

edit 4
Now tested under ubuntu too -> same effect. Still no idea why this is happening though. This is really a dealbreaker for me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:18:54+00:00Added an answer on June 8, 2026 at 8:18 am

    At startup a large number of java.lang.reflect.Method objects are created.

    heap dump

    These objects are eligible for garbage collection, but in the case of your application it probably causes too many eden collections which results in high startup times.

    Most of these java.lang.reflect.Method objects are allocated at the following site:

    allocation sites for java.lang.reflect.Method objects

    These seem to be created when Spring tries to find setters on AnnotationConfigTestFrame which inherits lots of methods from java.awt and javax.swing super classes. I did not read through the relevant code closely, but as a quick test to verify this hypothesis, I did the following:

    @Service
    public class AnnotationConfigTestFrame /* extends JFrame */
    {
        public static void main(String[] args) throws InterruptedException
        {
            ApplicationContext ctx = new AnnotationConfigApplicationContext(AnnotationConfigTestFrame.class);
    
            AnnotationConfigTestFrame frame = (AnnotationConfigTestFrame) ctx
                    .getBean("annotationConfigTestFrame");
    //        frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    //        frame.setVisible(true);
    
            waitABit();
            printRuntimeStats();
            System.exit(0);
        }
    }
    

    i.e. made AnnotationConfigTestFrame not inherit from javax.swing.JFrame. Now the memory usage for looking up the bean is reasonably low!

    This might give you hints for debugging this further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noticed a strange thing today. I have some code like this in a project
Noticed this today when a patch was submitted with the following line: lblCompletionTime.Text =
I noticed that Clojure (1.4) seems to be happy to consider vectors equal to
I noticed that IE 9 does not support application cache. How can I use
I have the following problem in application express which is driving me crazy: I
This only happens from time to time, seems random and I have not been
This is driving me crazy already and by now I'm absolutely hopeless :( Here
I noticed that every tutorial on how to do JavaScript inheritance does this: SubClass.prototype
I noticed that itertools does not (it seems to me) have a function capable
NEW INFO: Something I just noticed (because this isn't something I'd normally do), but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.