You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2019/12/30 22:17:46 UTC

[GitHub] [logging-log4j2] carterkozak commented on a change in pull request #327: LOG4J2-2752: MutableLogEvent and RingBufferLogEvent lazily create buffers

carterkozak commented on a change in pull request #327: LOG4J2-2752: MutableLogEvent and RingBufferLogEvent lazily create buffers
URL: https://github.com/apache/logging-log4j2/pull/327#discussion_r362109710
 
 

 ##########
 File path: log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
 ##########
 @@ -416,12 +409,18 @@ public void clear() {
         }
 
         // ensure that excessively long char[] arrays are not kept in memory forever
-        StringBuilders.trimToMaxSize(messageText, Constants.MAX_REUSABLE_MESSAGE_SIZE);
+        if (Constants.ENABLE_THREADLOCALS) {
+            StringBuilders.trimToMaxSize(messageText, Constants.MAX_REUSABLE_MESSAGE_SIZE);
 
-        if (parameters != null) {
-            for (int i = 0; i < parameters.length; i++) {
-                parameters[i] = null;
+            if (parameters != null) {
+                Arrays.fill(parameters, null);
             }
+        } else {
+            // A user may have manually logged a ReusableMessage implementation, when thread locals are
+            // disabled we remove the reference in order to avoid permanently holding references to these
+            // buffers.
+            messageText = null;
+            parameters = null;
 
 Review comment:
   Previously this allowed for unexpected growth, though bounded by the ring buffer size.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services