How to Measure The Amount of Leaked Memory?
I am writing codes to measure approximate how much
memory is leaked when I call some methods. But I am
not sure which method I should use for that in Runtime
class.
My codes are like:
Runtime rtStart = Runtime.getRuntime();
rtStart.gc();
//total memory at starting time
long tmemStart = rtStart.totalMemory();
//free memory at starting time
long fmemStart = rtStart.freeMemory();
//used memory at starting time
long usedMemStart = tmemStart - fmemStart;
//call methods here do something
Runtime rtEnd = Runtime.getRuntime();
rtEnd.gc();
//total memory at end time
long tmemEnd = rtEnd.totalMemory();
//free memory at end time
long fmemEnd = rtStart.freeMemory();
//used memory at starting time
long usedMemEnd = tmemEnd - fmemEnd;
//total memory difference
long totalMem = tmemStart - tmemEnd;
//free memory difference
long freeMem = fmemStart - fmemEnd;
//used memory difference
long usedMem = usedMemEnd - usedMemStart;
Does anybody know which one is the correct answer for
the approximate amount of memory leakage or there is
another measure for it? Thanks in advance.
Cheryl

