Search code examples
springjsr250

JSR-250 lifecycle annotations: Annotation Type PreDestroy


Is the method @PreDestroy of a prototype bean called when the bean is garbage collected ?


Solution

  • No, it is not called when the bean is garbage collected but for the bean to be garbage collected it has to be dereferenced first, which would mean it would have to be destroyed and @PreDestroy be called.

    So the method won't be called directly but it has to have been called before being garbage collected