You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/16 14:38:57 UTC

[40/50] logging-log4j2 git commit: LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional very long messages do not result in large char[] arrays being held by the RingBuffer forever

LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional very long messages do not result in large char[] arrays being held by the RingBuffer forever


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/69999c22
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/69999c22
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/69999c22

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 69999c2278bbefdace942ea5de9683226c14b5fe
Parents: 05adeef
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 03:10:31 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/RingBufferLogEvent.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/69999c22/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index e918500..32d73d9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -338,6 +338,12 @@ public class RingBufferLogEvent implements LogEvent {
                 null,
                 0, 0 // nanoTime
         );
+
+        // ensure that excessively long char[] arrays are not kept in memory forever
+        if (messageText != null && messageText.length() > 258) { // resized more than once from 128 (s=s*2+2)
+            messageText.setLength(258);
+            messageText.trimToSize();
+        }
     }
 
     private void writeObject(final java.io.ObjectOutputStream out) throws IOException {