public static long memoryUsageOf(Instrumentation inst,final Object obj){
  return inst.getObjectSize(obj);
}

public static long memoryUsageOf ( Instrumentation inst , final Object obj ) { return inst . getObjectSize ( obj ) ; }
returns an estimation of the " shallow " memory usage , in bytes , of the given object . the estimate is provided by the running jvm and is likely to be as accurate a measure as can be reasonably made by the running java program . it will generally include memory taken up for " housekeeping " of that object . the shallow memory usage does not count the memory used by objects referenced by obj .
