Wednesday, September 19, 2018

How to calculate memory used by an object

this article required classmexer.
before start make sure download the classmexer dependency from here or classmexer 0.0.3.

1. extract and put the classmexer.jar in classpath.
2. call classmexer api to calculate memory usage.


Product p= retrieveProductFromDB();


System.out.println("Size of product is " + MemoryUtil.deepMemoryUsageOf(p));

System.out.println("Size of product is " + MemoryUtil.deepMemoryUsageOf(p, VisibilityFilter.ALL));

System.out.println("Size of product is " + MemoryUtil.memoryUsageOf(p));



Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...