Please go through the official documentation for free memory and total memory
docs
Free Memory:
public long freeMemory()
: Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.
Returns:
an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.
Total Memory:
public long totalMemory()
Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.
Returns:
the total amount of memory currently available for current and future objects, measured in bytes.
If you want to find out the memory used by your Object, then you have to
calculate by subtracting totalMemory - freeMemory as i shown below.
System.out.prinltn("Memory Used by the Person Object" +
Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());