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 6367481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:33:10+00:00 2026-05-25T00:33:10+00:00

I have configured a Spring app (using Camel for integration with an ActiveMQ broker)

  • 0

I have configured a Spring app (using Camel for integration with an ActiveMQ broker) such that two particular classes, say, Person and Personality, get wired-up and injected with all of their dependencies automatically through the Spring container. For the sake of this example, Person objects have Personality objects as members/properties. So the Spring config file wires up Personality instance, and those beans are referenced in the wired People beans:

<bean id="personality" class="com.me.someProgram.Personality" singleton="false">
    <!-- blah... -->
</bean>

<bean id="person" class="com.me.someProgram.Person" singleton="false">
    <!-- People have Personalities -->
    <property name="personality" ref="personality"/>
    <!-- blah... -->
</bean>

Both beans are specified as prototypes in scope because this makes sense for my application. Basically, I need to grab a new instance of Personality every time I get a new Person.

My question:

This is my first application using Spring, and IoC/dependency injection in general. I am worried about garbage collection and memory leaks. When beans are prototypes, and you have prototypes nested inside of prototypes (via has-a relationship), do you have to worry about GC/memory leaks? Or does the Spring container alleviate all of those concerns for you? Are there best practices with regards to Spring/IoC memory management? Any anti-patterns to steer clear of?

My actual business objects are quite large, and I will produce many of them, so if I start heading down a road that is riddled with bad memory management, it’s going to be a very, very bumpy ride.

Thanks!

  • 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-05-25T00:33:10+00:00Added an answer on May 25, 2026 at 12:33 am

    There will be no issues with garbage collection in the above code that are caused by spring. You can think of the spring config above as another way of saying,

    Personality personality = new Personality();
    Person person = new Person();
    person.setPersonality(person);
    

    Spring does not maintain a reference to prototype beans it creates, so spring itself will not cause a memory leak.

    Spring does maintain references to singleton scoped beans, and those will not be gc’d until the containing application context is.

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

Sidebar

Related Questions

I am using spring to initialise my beans. I have configured a bean which
I have a portlet application. It is configured using Spring framework IoC container. I
I have a c# library project, that i configured using nhibernate, and I like
I have a small Spring app that reads a few databases, and writes a
I have a grails app configured with spring-security-core and I need to allow Facebook
I have configured my default page to be say abcd.aspx and is under ~/View//abcd.aspx
I have configured Tomcat 6 to serve Perl CGI scripts. That part is well
I have configured my Django app to run under Apache+FastCGI on Linux (Ubuntu, if
Using IDEA and tomcat I setup a simple spring mvc app (thanks to you
I have an internal website that is using integrated windows authentication and this website

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.