+1 Makes sense to me.

(If anyone else is wondering too: Component doesn't implement IDetachable because if it did, we'd run in an infinite loop when models reference components.)

Sven

On 11/13/2012 03:58 PM, Martin Grigorov wrote:
Hi,

The debug panel in wicket-devutils uses WicketObjects#sizeOf() to calculate
the size of the page and the session.

The "problem" that I see is that it calculates the size of the non-detached
object. I think what really matters is the size after detaching it, because
this is what is being saved in the http session and the disk, and I guess
this is what the developer needs to know actually.

Since #detach() can be called at any time, and several times per request
processing I suggest the following change:

---
a/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java
+++
b/wicket-core/src/main/java/org/apache/wicket/core/util/lang/WicketObjects.java
@@ -31,6 +31,7 @@ import org.apache.wicket.Application;
  import org.apache.wicket.Component;
  import org.apache.wicket.WicketRuntimeException;
  import org.apache.wicket.application.IClassResolver;
+import org.apache.wicket.model.IDetachable;
  import org.apache.wicket.serialize.ISerializer;
  import org.apache.wicket.serialize.java.JavaSerializer;
  import org.apache.wicket.settings.IApplicationSettings;
@@ -416,6 +417,15 @@ public class WicketObjects
          */
         public static long sizeof(final Serializable object)
         {
+               if (object instanceof Component)
+               {
+                       ((Component) object).detach();
+               }
+               else if (object instanceof IDetachable)
+               {
+                       ((IDetachable) object).detach();
+               }
+
                 return objectSizeOfStrategy.sizeOf(object);
         }


Do you see any problems with this ?


Reply via email to