How big is an Object, without making use of a profiler
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/52353/in-java-what-is-the-best-way-to-determine-the-size-of-an-object">In Java, what is the best way to determine the size of an object?</a>  </p>
</blockquote>



<p>I found this piece of code on the net:</p>

<pre><code>static Runtime runtime = Runtime.getRuntime();
...
long start, end;
Object obj;
runtime.gc();
start = runtime.freememory();
obj = new Object(); // Or whatever you want to look at
end =  runtime.freememory();
System.out.println("That took " + (start-end) + " 
bytes.");
</code></pre>

<p>But it is not very reliable, any idea on how to do it better?</p>
