• Post Reply Bookmark Topic Watch Topic
  • New Topic

any very simple memory-eating type test code ?  RSS feed

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a helloworld type simple code to test how quickly the memory is used up. I may run several some processes at the same time to test how long the system can sustain. Can somebody provide such sample ?
 
Jared White
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this recursive call. I extended JFrame only because I think that it is an object that can take a good chunk of memory.
When I ran this it created a StackOverflowError.
I hope this is what you are looking for.

import javax.swing.JFrame;
public class MemoryEater extends JFrame{

public static void main(String[] args) {
MemoryEater eater = new MemoryEater();
eater.eat();
}

public void eat(){
MemoryEater eater = new MemoryEater();
eater.eat();
}
}
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm... I wouldn't think a stack overflow is the same as a memory problem...

by calling it recursivley you're simply loading up the callstack and thus you get a stack overflow...
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you don't want to increase memory use exponentially you could just append a fixed-length String. Or possibly fill a Map with Strings if you don't want just one massive object.


--tim
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Date is just an example, I'm sure there are heavier classes to use instead that will eat memory more quickly
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!