abu-tahir-0 opened a new pull request, #4524: URL: https://github.com/apache/logging-log4j2/pull/4524
## Problem `DefaultThreadContextMap.remove()` and `removeAll()` retain an empty backing array in a `ThreadLocal` after the final entry is removed. Long-lived threads keep that state alive unnecessarily. ## Root cause Both methods unconditionally replaced the `ThreadLocal` value with the copied map's backing array, even when the resulting immutable map was empty. ## Solution Remove the `ThreadLocal` entry when the resulting map is empty; otherwise retain the non-empty backing array. Add tests for single-key, multi-key, `removeAll`, partial removal, and repeated removal, plus the 2.x changelog entry. ## Testing - Agent verification: 4 new tests failed before the fix; `DefaultThreadContextMapTest` 20 passed; `ThreadContextTest` 14 passed; garbage-free map tests 9 passed in four executions. - Spotless, changelog validation, and `git diff --check` passed. - Full `verify site` was not run. Fixes #2523 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
