What is the fastest way to consume enough memory to force an application to reset the OS?

I have an application that I call eater memory, which is designed to force the removal of other os applications. It does this by consuming a lot of memory over time, until it stops due to memory pressure. In order to consume memory, I basically make copies of JPEG data representations:

-(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 completely with trial and error, and I assume that there is an easier way to consume a lot and a lot of memory.

+5
source share
1 answer

You can use malloc() in a loop.

 while (1) { int *ptr = malloc(4096); assert(ptr != NULL); *ptr = 0; } 

The *ptr = 0 necessary for the page to be dirty, otherwise you will use the address space instead of memory. The number 4096 ensures that each iteration through the loop adds exactly one dirty page to the address space, since 4096 is the most common page size.

+6
source

Source: https://habr.com/ru/post/1200291/


All Articles