Inherited fields not handled.

  • Jonathan Hsieh

    Jonathan Hsieh - 2008-11-21

    Here's a rough example that shows what i think the problem is:

    class A {
      byte[5000] foo;

    class B extends A {
      byte[1000] bar;

    B b = new B();
    assert(SizeOf.deepSizeOf(b) > 6000); // fails.  size is closer 1000+

    Basically, deepSizeOf doesn't get superclass fields.

    Here's the gist of a fix that I added to my copy:

    -- replace this line in deepSizeOf
         Field[] fields = o.getClass().getDeclaredFields();
    -- with this
        for (Class<?> clz = o.getClass(); clz != null; clz = clz.getSuperclass()) {
            Field[] fields = clz.getDeclaredFields();
    -- and enclose loop with '}' after the Field loop.

  • Anonymous - 2011-12-20

    Thank you for the useful tools. It's good to use in web application(JBoss). But I don't know how to use in a java application in Eclipse. It add th argument: -javaagent:<path to>/SizeOf.jar to Run Configuration. But a error shows "Unrecognized option: -javaagent". The famouse Exception(Instrumentation is null)  will happen if I don't add the argumnet.I searched this error on google and this many forums, but I failed. Anybody help me?
    my email is Thank you again!


Log in to post a comment.