Announcement Announcement Module
No announcement yet.
Aspects scanning too many classes and method cache fills memory Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aspects scanning too many classes and method cache fills memory

    Hi Spring Comunity!

    I hope I can use some of your help in explaining the below situation.

    In our application we have several (actuall many, about 30) web services. Each web service resides in its own WAR file and has its own Spring context that is initialised when application starts.

    We also have a number of annotation-driven aspect classes that we apply to web service classes. In the begining the poincut expression looked like this:

    @Pointcut("execution(public **BusinessServiceImpl.*(..))")
      public void methodsToBeLogged() {
    And AOP was enabled on services through <aop:aspectj-autoproxy /> entry in configuration.

    But when the number of web serivces grew, we began to experience OutOfMemoryExceptions on our servers. After doing some profiling and analysis it appeared that memory is taken by the cache that is kept by instances of AspectJExpressionPointcut class.

    Each instance's cache was about 5 MBs. And as we had 3 aspects and 30 services it resulted in 90 instances holding 450MBs of data in total.

    After examining the contents of the cache we realised that it contains Java reflection Method instances for all classes existing in the WAR even those which are not part of package. After modifing the point cut expression to:

    @Pointcut("execution(public **BusinessServiceImpl.*(..)) && 
      public void methodsToBeLogged() {
    Memory usage was down to normal again. And all AspectJExpressionPointcut instances took less than 1MB all together.

    Can someone explain why is that? And why first point cut expression is not enough? Why the cache of AspectJExpressionPointcut is not shared?

    Best regards,

  • #2
    Issue is described in
    and also in