title: Do Spring prototype beans need to be destroyed manually?
body: <p>I noticed that the <code>@PreDestroy</code> hooks of my prototype scoped Spring beans were not getting executed.</p>
  
  <p>I have since read <a href="https://docs.spring.io/spring/docs/4.3.9.RELEASE/spring-framework-reference/html/beans.html#beans-factory-scopes-prototype" rel="noreferrer">here</a> that this is actually by design.  The Spring container will destroy singleton beans but will not destroy prototype beans.  It is unclear to me why.  If the Spring container will create my prototype bean and execute its <code>@PostConstruct</code> hook, why will it not destroy my bean as well, when the container is closed?  Once my Spring container has been closed, does it even make sense to continue using any of its beans?  I cannot see a scenario where you would want to close a container before you have finished with its beans.  Is it even possible to continue using a prototype Spring bean after its container has been closed?</p>
  
  <p>The above describes the puzzling background to my primary question which is:  If the Spring container is not destroying prototype beans, does that mean a memory leak could occur?  Or will the prototype bean get garbage-collected at some point?</p>
  
  <p>The Spring documentations states:</p>
  
  <blockquote>
    <p>The client code must clean up prototype-scoped objects and release
    expensive resources that the prototype bean(s) are holding. To get the
    Spring container to release resources held by prototype-scoped beans,
    try using a custom bean post-processor, which holds a reference to
    beans that need to be cleaned up.</p>
  </blockquote>
  
  <p>What does that mean?  The text suggests to me that I, as the programmer am responsible for explicitly (manually) destroying my prototype beans.  Is this correct?  If so, how do I do that?</p>