Hello developer, in our production practice, I found that the attribute shadowMatchCache of AspectJExpressionPointcut occupies a large amount of memory. We have more than 20 facets, and each facet will save an object shadowMatchCache, which is a map type. Each map object occupies nearly 8M of memory, totaling about 150M of memory. This causes us to experience memory overflow when setting lower memory. Please see the following figure

Spring Field shadowMatchCache of AspectJExpressionPointcut Occupied a large amount of memory Thank you for helping me figure out how to reasonably avoid this issue. I see that Spring 6 has already fixed this problem. In the AspectJAwareAdvisorAutoProxyCreator class, I released it through reflection when calling the afterSingletonsIntitated method. However, when I started my project, I ran out of memory before I could clear it. I don't have a better solution now, and I hope to get your help. Thank you

Comment From: snicoll

@MrWanglu what version of Spring Framework are you using? What is a "facet"? The fix you are referring to (#12334) was meant to fix the problem when using a lot of different test contexts.

Comment From: MrWanglu

my spring version is 5.3.31, sorry My mistake! the "facet" I means that is aspect[@Aspect], our project has 22 aspects, I saw this issue which you sent to me,but when i start my project,OutOfMemory before I clear the shadowMatchCache

Comment From: MrWanglu

I clear shadowMatchCache in afterSingletonsInstantiated method, But the memory overflowed before it was cleared

Comment From: snicoll

but when i start my project,OutOfMemory before I clear the shadowMatchCache

It's unclear why you think the shadow cache is responsible for this. Spring 6 didn't fix anything if the shadow cache is the component that's preventing your app to start. How did you come to that conclusion? Can you run your app with more memory? How much memory does the app can use at the moment?

Comment From: MrWanglu

Thank you for your reply. After thinking about it, I realized that this is not a problem with the framework. I raised this issue because I wanted to save memory as much as possible. Thank you for your patient reply, and I will close this issue