Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50228
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Nov 2010 17:40:09 +0000 (17:40 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Nov 2010 17:40:09 +0000 (17:40 +0000)
Improve recycling of BodyContentImpl.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1037794 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/runtime/BodyContentImpl.java
java/org/apache/jasper/runtime/PageContextImpl.java

index 153ee0d..d9fb0f8 100644 (file)
@@ -605,7 +605,27 @@ public class BodyContentImpl extends BodyContent {
             clearBody();
         }
     }
-    
+
+    /**
+     * This method shall "reset" the internal state of a BodyContentImpl,
+     * releasing all internal references, and preparing it for potential
+     * reuse by a later invocation of {@link PageContextImpl#pushBody(Writer)}.
+     *
+     * <p>Note, that BodyContentImpl instances are usually owned by a
+     * PageContextImpl instance, and PageContextImpl instances are recycled
+     * and reused.
+     *
+     * @see PageContextImpl#release()
+     */
+    protected void recycle() {
+        this.writer = null;
+        try {
+            this.clear();
+        } catch (IOException ex) {
+            // ignore
+        }
+    }
+
     private void ensureOpen() throws IOException {
         if (closed) throw new IOException("Stream closed");
     }
index c030910..f7a0a63 100644 (file)
@@ -204,6 +204,9 @@ public class PageContextImpl extends PageContext {
             baseOut.recycle();
             session = null;
             attributes.clear();
+            for (BodyContentImpl body: outs) {
+                body.recycle();
+            }
         }
     }