There are so many things wrong with that, I don't even know where to start.
Okay. Let's try one thing: you assign values to three long variables, then you do some String concatenations, then you create a StringBuilder object. And you assume the difference between the free memory before this and the free memory after that is... the amount of memory used by a long variable?
Let's try another thing: the space for local variables is allocated at the start of the method. So even if you didn't create all those other objects, you still wouldn't be measuring the space required for a long variable.
And rounding your numbers down to the next lower multiple of 1024 isn't going to help you tell if a long variable requires 8 or 16 bytes.
Joined: Jun 28, 2009
Thanks for the answer. I tried this..is this the same...