public static long shallowSizeOf(Object obj){
  if (obj == null)   return 0;
  final Class<?> clz=obj.getClass();
  if (clz.isArray()) {
    return shallowSizeOfArray(obj);
  }
 else {
    return shallowSizeOfInstance(clz);
  }
}

public static long shallowSizeOf ( Object obj ) { if ( obj == null ) return 0 ; final Class < ? > clz = obj . getClass ( ) ; if ( clz . isArray ( ) ) { return shallowSizeOfArray ( obj ) ; } else { return shallowSizeOfInstance ( clz ) ; } }
estimates a " shallow " memory usage of the given object . for arrays , this will be the memory taken by array storage ( no subreferences will be followed ) . for objects , this will be the memory taken by the fields . jvm object alignments are also applied .
