Suvrat1629 commented on code in PR #3474: URL: https://github.com/apache/logging-log4j2/pull/3474#discussion_r1965743880
########## log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java: ########## @@ -53,23 +57,48 @@ public final class InternalLoggerRegistry { new WeakHashMap<>(); private final ReadWriteLock lock = new ReentrantReadWriteLock(); - private final Lock readLock = lock.readLock(); - private final Lock writeLock = lock.writeLock(); + // ReferenceQueue to track stale WeakReferences + private final ReferenceQueue<Logger> staleLoggerRefs = new ReferenceQueue<>(); + public InternalLoggerRegistry() {} + /** + * Expunges stale logger references from the registry. + */ + private void expungeStaleEntries() { + Reference<? extends Logger> loggerRef; + while ((loggerRef = staleLoggerRefs.poll()) != null) { + removeLogger(loggerRef); + } + } + + /** + * Removes a logger from the registry. + */ + private void removeLogger(Reference<? extends Logger> loggerRef) { + writeLock.lock(); + try { + loggerRefByNameByMessageFactory.values().forEach(map -> map.values().removeIf(ref -> ref == loggerRef)); + } finally { + writeLock.unlock(); + } Review Comment: Well you are right this is a bit inefficient. I have made some changes to the `removeLogger`, please take a look if it fits fine. -- 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