1

Like CPU simulation I need to write an application that can simulate high memory-usage at a pre-set values ( e.g., 30%, 50%, 90% etc) for a certain duration. Meaning it will take two inputs (memoryvalue and duration). Let say i use 50% for memory-Usage and 2 minutes for Duration). This mean that when I run the application, it should take 50% memory for 2 minutes. Any ideas how this can be achieved?

Any help pls.

wbi
  • 40
  • 2
  • 4

1 Answers1

0

You can simulate a memory leak like this (taken from this thread):

var list = new List<byte[]>();
while (true)
{
  list.Add(new byte[1024]); // Change the size here.
}

Similarly to the app I wrote for simulating CPU load for a specific amount of time, you just make a method allocating an amount of memory and create a timer, which when it runs out, clears the list and then invokes the Garbage Collector.

You have to watch out that if you allocate too much memory your system might become unresponsive and you might crash it.

Community
  • 1
  • 1
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118