I have an app I call memory eater, which is meant to force other applications to be dumped by the os. It does this by consuming lots of memory over time until it is terminated due to memory pressure. In order to consume memory I basically make copies of JPEG representations of data:
-(IBAction)didTapStartButton:(id)sender{
int i = 200;
while (i>0) {
NSData* data = [UIImagePNGRepresentation(self.image) mutableCopy] ;
[self.array addObject:[[data description] mutableCopy]];
[self.array addObject:data];
i--;
}
}
This was done entirely with trial and error, and I assume that there is a more straightforward way to consume lots and lots of memory.
Enable memory dump settingIn Control Panel, select System and Security > System. Select Advanced system settings, and then select the Advanced tab. In the Startup and Recovery area, select Settings. Make sure that Kernel memory dump or Complete memory dump is selected under Writing Debugging Information.
A complete memory dump records all the contents of system memory when your computer stops unexpectedly. A complete memory dump may contain data from processes that were running when the memory dump was collected.
You can use malloc()
in a loop.
while (1) {
int *ptr = malloc(4096);
assert(ptr != NULL);
*ptr = 0;
}
The *ptr = 0
line is necessary to force the page to be dirty, otherwise you will consume address space instead of memory. The number 4096 ensures that each iteration through the loop will add exactly one dirty page to the address space, since 4096 is the most common page size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With