shaonan666 commented on issue #3569: URL: https://github.com/apache/logging-log4j2/issues/3569#issuecomment-2751097993
Hi @ppkarwasz My program isn’t a web app, so [Constants#isWebApp](https://logging.apache.org/log4j/2.x/manual/garbagefree.html#log4j2.isWebapp) returns false at runtime, setting `log4j2.enableThreadlocals `to true. I didn’t intend to enable GC-free mode, it happened accidentally because my program isn’t a `web app`, resulting in “half” of GC-free mode being enabled. Now I understand that to fully enable GC-free mode, I also need to set `log4j2.garbagefreeThreadContextMap` to true. Additionally, I’ve noticed some version differences: - In `2.23.1`, if `log4j2.garbagefreeThreadContextMap` isn’t enabled, it returns [CopyOnWriteSortedArrayThreadContextMap](https://github.com/apache/logging-log4j2/blob/fea2a7116160fb1555d578406444b4fc4f0ef2da/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java) by this [logic](https://github.com/apache/logging-log4j2/blob/fea2a7116160fb1555d578406444b4fc4f0ef2da/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMapFactory.java#L140-L144). - In `2.24.3` , if `log4j2.garbagefreeThreadContextMap` isn’t enabled, the program is temporarily identified as a 'WEB_APP_CONTEXT_MAP' and ultimately returns DefaultThreadContextMap. (see [Log4jProvider.java](https://github.com/apache/logging/log4j2/blob/4aa5efec7f2ee2d4623381cd66c3df3a16a6b9a9/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jProvider.java#L111-L143), lines 111-143) Based on these observations, I have the some questions: - Could the difference between `DefaultThreadContextMap` and `CopyOnWriteSortedArrayThreadContextMap` be the reason I’m seeing an increase in memory usage? Could you briefly explain the differences between these two classes? - Under the same configuration (not a web app), when `log4j2.garbagefreeThreadContextMap` isn’t enabled, memory usage in 2.24.3 seems less stable compared to 2.23.1. Is this an expected change? - Could you kindly explain the difference between DefaultThreadContextMap and CopyOnWriteSortedArrayThreadContextMap in simple terms? I’ve noticed they affect memory usage, and I’d like to understand why. -- 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