#Memory leak with prototype scoped beans

23 messages · Page 1 of 1 (latest)

pseudo onyx
#

While recently working on a spring boot application, I noticed a certain prototyped bean is causing a severe memory leak.
The bean in question was created at runtime using ApplicationContext.getBean(...) However, when the bean falls out of scope, the FastClass subclasses/proxies created for the Enhancer and the bean itself still persists and never GCed. This is very strange since the bean and its Enhancer are already GCed. Does anyone every encounter this issue, or have any idea what the cause might be?

hushed sageBOT
#

This post has been reserved for your question.

Hey @pseudo onyx! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mystic hinge
#

⛹️‍♂️

pseudo onyx
#

what does that mean, friend

mystic hinge
#

or

#

Eclipse Memory Analyzer to analyze a heap dump!

pseudo onyx
#

I have done that, the root of the problem seems to be spring cglib creating a new enhancer for every prototype bean! This is a disaster because the enhancer has many static method proxies which never dies for as long as the Class is being referenced. I have no idea why spring creates so many enhancer classes though.

mystic hinge
#

hmmm........got it!

#

if CGLIB is creating a new Enhancer for every prototype bean, this could potentially lead to a memory leak if the Enhancer and its associated proxies are not being properly garbage collected!

#

hit me Dms!

pseudo onyx
#

Hello friend, I'd much rather discuss potential fixes here. In case other people might find it helpful

mystic hinge
#

alright!

#

first create the prototyype beans to see if there is any unnnecessary or excessive creation of beans!

hushed sageBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

pseudo onyx
#

it turns out, spring boot devtools lib makes spring use a RestartClassLoader to create its beans. this class loader is considered a "smart" and reloadable, thus the prototype bean proxies are cached but never reused

#

i will see if i can completely disable this behavior and see if it's fixed

pseudo onyx
#

issue appears to be fixed. ReloadClassLoader was the culprit