Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I find a MemoryConsumer.java program to test consumption of memory?

Where do I find a MemoryConsumer.java program to test consumption of memory? I know that such a thing already exists , as I see references via Google to such things. For example, this Oracle site refers to "ConsumeHeap.java" but I don't know where to find that source code.

hotspot 1.6 options

Does anyone know where to find or how to create such a thing?

like image 701
djangofan Avatar asked Dec 09 '25 15:12

djangofan


2 Answers

I've used this ObjectSizer class to good effect:

http://www.javapractices.com/topic/TopicAction.do?Id=83

It works by creating huge amounts of object instances, as suggested by Tyler.

like image 193
Sam Barnum Avatar answered Dec 11 '25 04:12

Sam Barnum


You could simply create a huge amount of object instances and keep them in scope.

ArrayList<SomeObject> listOfObjects = new ArrayList<SomeObject>;
for (int i = 0; i < aBigNumber; i++) {
  listOfObjects.add(new SomeObject());
}
like image 28
Tyler Holien Avatar answered Dec 11 '25 03:12

Tyler Holien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!