You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "muarine (via GitHub)" <gi...@apache.org> on 2026/01/20 06:20:23 UTC
[I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
muarine opened a new issue, #13676:
URL: https://github.com/apache/skywalking/issues/13676
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues.
### Apache SkyWalking Component
Java Agent (apache/skywalking-java)
### What happened
Environment
- SkyWalking Agent: 9.4(你实际版本)
- JVM: JDK 17
- Application type: Spring Boot 3.4.2
- Message middleware: RocketMQ
- OS: Linux
Problem Description
Heap dump analysis shows that ~97% of heap memory is retained by
org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder.
SWDescriptionStrategy$SWTypeDescriptionWrapper
via CLASS_LOADER_TYPE_CACHE (ConcurrentHashMap).
The cache holds ~5.8 million TypeDescription entries and is
strongly referenced without size limit.
MAT Dominator Tree shows:
- CLASS_LOADER_TYPE_CACHE retained heap: ~3.8GB
- Entry count: ~5.8 million
- Other components (Spring, RocketMQ, MyBatis) are negligible
### What you expected to happen
Is it expected for CLASS_LOADER_TYPE_CACHE to be unbounded?
Would it be possible to:
- introduce weak references, or
- add a size limit / eviction strategy, or
- provide an agent configuration to disable or limit such caching?
We would like to confirm whether this behavior is by design
or could be improved to avoid memory risk in dynamic-class-heavy workloads.
### How to reproduce
1. Prepare a Spring Boot application with SkyWalking Java agent enabled.
2. Use JDK 11+ (JDK 17 recommended).
3. Initialize a large number of MessageConsumers (or similar components)
using anonymous classes or lambda expressions.
For example, repeatedly create RocketMQ consumers like:
RocketMqBaseConsumer.builder()
.nameServer(...)
.topic(...)
.groupId(...)
.build()
.init(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(
List<MessageExt> msgs,
ConsumeConcurrentlyContext context) {
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
(Each init call creates a new anonymous MessageListener class.)
4. Ensure that:
- Consumers are initialized dynamically (e.g. on startup or configuration reload)
- A large number of such listeners are created over time (tens of thousands or more)
5. Run the application under normal workload for several hours.
6. Observe heap memory usage continuously increasing and not being released.
7. Take a heap dump and analyze with MAT:
- Dominator Tree shows
org.apache.skywalking.apm.dependencies.net.bytebuddy.agent.builder
.SWDescriptionStrategy$SWTypeDescriptionWrapper
retaining most of the heap.
- The retention path goes through
SWDescriptionStrategy.CLASS_LOADER_TYPE_CACHE (ConcurrentHashMap).
- Entry count grows monotonically with runtime-generated classes.
Replacing anonymous classes with a single reusable concrete listener
class prevents the cache growth, confirming the correlation with
runtime-generated classes.
### Anything else
_No response_
### Are you willing to submit a pull request to fix on your own?
- [ ] Yes I am willing to submit a pull request on my own!
### Code of Conduct
- [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
Posted by "muarine (via GitHub)" <gi...@apache.org>.
muarine commented on issue #13676:
URL: https://github.com/apache/skywalking/issues/13676#issuecomment-3775804940
> This issue has been fixed in the SkyWalking Java Agent by PR [apache/skywalking-java#772](https://github.com/apache/skywalking-java/pull/772).
>
> The fix changed `CLASS_LOADER_TYPE_CACHE` from `ConcurrentHashMap` to `WeakHashMap`, so when a ClassLoader is garbage collected, its cached TypeDescription entries are automatically cleaned up. This addresses the OOM issue for applications that dynamically generate many runtime classes (like lambdas and anonymous classes).
>
> The fix will be available in Java Agent version 9.6.0.
When is version 9.6.0 expected to be released
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
Posted by "muarine (via GitHub)" <gi...@apache.org>.
muarine commented on issue #13676:
URL: https://github.com/apache/skywalking/issues/13676#issuecomment-3775664119
Thank you for answering my doubts
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on issue #13676:
URL: https://github.com/apache/skywalking/issues/13676#issuecomment-3775831435
I am about to have my winter vacation soon, and I will release it when I am back in two weeks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on issue #13676:
URL: https://github.com/apache/skywalking/issues/13676#issuecomment-3772553107
This issue has been fixed in the SkyWalking Java Agent by PR https://github.com/apache/skywalking-java/pull/772.
The fix changed `CLASS_LOADER_TYPE_CACHE` from `ConcurrentHashMap` to `WeakHashMap`, so when a ClassLoader is garbage collected, its cached TypeDescription entries are automatically cleaned up. This addresses the OOM issue for applications that dynamically generate many runtime classes (like lambdas and anonymous classes).
The fix will be available in Java Agent version 9.6.0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated [skywalking]
Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng closed issue #13676: [Bug] Potential memory leak: unbounded CLASS_LOADER_TYPE_CACHE in SWDescriptionStrategy when many runtime classes are generated
URL: https://github.com/apache/skywalking/issues/13676
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org