Quick revision
The short answer
With prototype scope, the container creates a new instance every time the bean is requested, for example on each getBean() call or each injection point. It still injects dependencies and runs initialisation callbacks such as @PostConstruct, but then hands the object over and forgets it: it does not track prototype instances, so destroy callbacks like @PreDestroy are never called, and the caller is responsible for cleaning up any resources a prototype holds.
What to remember
In this answer, we saw that prototype scope gives a new instance on every request for the bean, with dependency injection, Aware callbacks, @PostConstruct and post-processors applied as usual. After that the container lets the object go: it keeps no reference, so @PreDestroy and other destroy callbacks never run, and the calling code must close any resources, for example with AutoCloseable and try-with-resources, or by asking the bean factory to destroy the instance explicitly.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With prototype scope, the container creates a new instance every time the bean is requested, for example on each getBean() call or each injection point. It still injects dependencies and runs initialisation callbacks such as @PostConstruct, but then hands the object over and forgets it: it does not track prototype instances, so destroy callbacks like @PreDestroy are never called, and the caller is responsible for cleaning up any resources a prototype holds.
Why this question is asked
Prototype is the second built-in scope after singleton, and it is the one people most often misunderstand. Developers expect it to behave like a singleton with more instances, including cleanup at shutdown, and are surprised when files stay open or threads keep running. Interviewers ask about it to check that we know the full lifecycle Spring manages for each scope. In this answer, we will recap what prototype scope is, watch the container create instances, see which lifecycle steps run and which do not, and look at how to clean up properly.
1A Quick Recap of Prototype Scope
A scope tells the container how many instances of a bean to create and how long to keep them. Singleton means one instance, cached for the life of the container. Prototype means no caching at all: every request for the bean produces a fresh object. A request for the bean is anything that asks the container for it, such as ctx.getBean(), an ObjectProvider.getObject() call, or an injection into another bean while that bean is being created.
We declare it with @Scope("prototype"), or with the constant ConfigurableBeanFactory.SCOPE_PROTOTYPE, on a @Component class or a @Bean method. Prototype beans are never created eagerly at startup, because there is nothing to cache; they are created only when asked for.
2Watching the Container Create Instances
The clearest way to see the behaviour is to log in each callback and ask for the bean twice.
Notice three things. Nothing is created at startup. Each getBean() runs the constructor with injected dependencies and then @PostConstruct, so the container does the full creation work. And when the context closes, no destroy callback runs for either instance.
3Why the Container Does Not Destroy Prototypes
For singletons, the container keeps a reference to every instance in its singleton cache and a list of beans that need destruction callbacks, and at shutdown it walks that list. For prototypes it keeps nothing. After creating and initialising the object, it returns it to the caller and drops its own reference. The reason is that it cannot know when the caller has finished with the object: a prototype could be used for a millisecond or held for the life of the application, and keeping references would also stop the garbage collector from freeing thousands of short-lived instances.
So the container acts like a factory for prototypes, not a manager. Once the prototype is handed out, the client code owns it. Destruction callbacks, including @PreDestroy, DisposableBean.destroy() and a custom destroy method, are configured but simply never called.
| Step | Singleton | Prototype |
|---|---|---|
| Created at startup | yes (unless lazy) | no, on each request |
| Dependencies injected | yes | yes |
Aware callbacks, @PostConstruct, init | yes | yes |
BeanPostProcessors and proxies | yes | yes |
| Cached and reused | yes | no |
@PreDestroy and destroy methods | yes, at shutdown | never called |
4Cleaning Up Prototype Resources
If a prototype holds something that needs closing, such as a file handle, a socket or a thread, the code that obtained it must close it. The simplest pattern is to make the prototype implement AutoCloseable and use try-with-resources at the call site.
If we want Spring's destruction callbacks to run for a particular instance, we can ask the bean factory to do it explicitly: AutowireCapableBeanFactory.destroyBean(instance) runs the destroy callbacks, including @PreDestroy, on an object we pass in. That is useful when the prototype already has @PreDestroy logic, but the caller still has to decide when to call it.
5Follow-up questions
If a singleton injects a prototype, how many prototype instances are there?
Just one per injection point, created when the singleton is created. Injection happens once, so the singleton keeps that same prototype instance for its whole life. To get a new instance per use, inject ObjectProvider<T> and call getObject(), or use @Lookup method injection or jakarta.inject.Provider.
Do BeanPostProcessors and AOP proxies apply to prototype beans?
Yes. Every new prototype instance goes through the full creation path, including BeanPostProcessors, so @Transactional, @Async and other proxy-based features work on prototypes. The proxy is created per instance, which adds a little cost to each creation.
Can a prototype bean have a singleton dependency?
Yes, and it is very common. The prototype receives the same shared singleton each time it is created. The reverse, a singleton depending on a prototype, is the case that needs care, because the singleton keeps whichever instance it got first.
6Conclusion
In this answer, we saw that prototype scope gives a new instance on every request for the bean, with dependency injection, Aware callbacks, @PostConstruct and post-processors applied as usual. After that the container lets the object go: it keeps no reference, so @PreDestroy and other destroy callbacks never run, and the calling code must close any resources, for example with AutoCloseable and try-with-resources, or by asking the bean factory to destroy the instance explicitly.
Open with
Prototype scope means the container creates a new instance every time the bean is requested: each getBean call, each ObjectProvider.getObject call, and each injection point when another bean is created.
Then, if they want more
Nothing is created at startup. For each new instance, Spring does the full creation work: it calls the constructor with dependencies, runs Aware callbacks, @PostConstruct and init methods, and applies BeanPostProcessors, so proxies like @Transactional still work. What it does not do is manage the instance afterwards.
It keeps no reference, because it cannot know when the caller is finished, and keeping references would also stop garbage collection. So destroy callbacks, @PreDestroy, DisposableBean and custom destroy methods, are never called for prototypes, even when the context closes. That means the caller owns the instance and must clean up anything it holds, like files, sockets or threads.
I usually make such a prototype AutoCloseable and use try-with-resources around ObjectProvider.getObject, or, if it already has destroy logic, call destroyBean on the bean factory explicitly. And I keep in mind that a prototype injected once into a singleton is only created once.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How does prototype scope behave, and what does the container not do for prototype beans?": https://scrivio-interview-library.netlify.app/spring-boot/bean-scopes/9cd5a7c61e/