org.apache.qpid.junit.extensions.util
Class SizeOf
java.lang.Object
org.apache.qpid.junit.extensions.util.SizeOf
public class SizeOf
- extends Object
SizeOf provides a static method that does its best to return an accurate measure of the total amount of memory used by
the virtual machine. This is calculated as the total memory available to the VM minus the actual amount used by it.
Before this measurement is taken the garbage collector is run many times until the used memory calculation stabilizes.
Generally, this trick works quite well to provide an accurate reading, however, it cannot be relied upon to be totally
accurate. It is also quite slow.
CRC Card
Responsibilities | Collaborations
|
---|
Calculate total memory used.
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SizeOf
public SizeOf()
runGCTillStableSeveralTimes
public static void runGCTillStableSeveralTimes()
- Makes 4 calls the
runGCTillStable()
method.
runGCTillStable
public static void runGCTillStable()
- Runs the garbage collector until the used memory reading stabilizes. It may run the garbage collector up
to 500 times.
getUsedMemory
public static long getUsedMemory()
- Runs the garbage collector until the used memory stabilizes and then measures it.
- Returns:
- The amount of memory used by the virtual machine.
Licensed to the Apache Software Foundation