shaonan666 commented on issue #3569: URL: https://github.com/apache/logging-log4j2/issues/3569#issuecomment-2754340901
I think I’ve got it. Let me describe what happened again to ensure I fully understand. **My program doesn’t specify a `messageFactory`.** In version 2.23.1, `LoggerContext#getLogger(String name) `ultimately initializes a `ParameterizedMessageFactory` https://github.com/apache/logging-log4j2/blob/fea2a7116160fb1555d578406444b4fc4f0ef2da/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L493-L495 https://github.com/apache/logging-log4j2/blob/fea2a7116160fb1555d578406444b4fc4f0ef2da/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java#L134-L137 In version 2.24.3, `LoggerContext#getLogger(String name) ` uses a GC-free-compliant `ReusableMessageFactory` based on the configuration `log4j2.enableThreadlocals=true` https://github.com/apache/logging-log4j2/blob/4aa5efec7f2ee2d4623381cd66c3df3a16a6b9a9/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L93-L97 https://github.com/apache/logging-log4j2/blob/4aa5efec7f2ee2d4623381cd66c3df3a16a6b9a9/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L538-L540 These two different MessageFactory implementations are the main reason I’ve observed a gradual increase in memory usage: to support GC-free, `ReusableMessageFactory` allocates objects that aren’t released until all `RingBufferLogEvent` instances have been used at least once, at which point the memory growth stops. --- >Do you expect Log4j Core to pre-allocate StringBuilders of size [log4j2.initialReusableMsgSize](https://logging.apache.org/log4j/2.x/manual/garbagefree.html#log4j2.initialReusableMsgSize) instead of doing it on-demand? Pre-allocating a suitably sized `StringBuilder` based on prediction could be a good choice for services with high runtime latency requirements. But my main concern is the gradual memory increase in version 2.24.3, which I didn’t see in 2.23.1, and I initially suspected a memory leak. However, based on the current situation, it doesn’t seem to be a memory leak risk. I’m considering reducing the RingBuffer size to manage memory usage. Thank you for your patient explanations! -- 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-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org