Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to send Memory Warning to iPhone device manually? [duplicate]

I got one problem these days. I'm using an image-cache library, it works well but eventually i met memory issue and the app just quit itself (I guess it's because it just runs out of memory). After read the source code from the image-cache library, i found it's said that when there's memory warning event, it would release all images cached (the images are huge). Is there anyway for me to send Memory warning event to the device manually and directly ? I'm using xcode instrument tool to evaluate the memory usage.

like image 754
Kevin Xue Avatar asked Dec 07 '11 05:12

Kevin Xue


People also ask

How do I simulate memory warning in Xcode?

To simulate the memory warning we need to enable the toggle when the app runs on the simulator. To enable the logger for memory warnings, please run the app onto the simulator and then go to Debug → Simulate Memory Warning.

What is memory warning?

onLowMemory() raises when the system global memory is low. If the global memory is okay but your process takes more than 24MB on old Android devices, it will crash and you'll never get a low memory warning.


1 Answers

You can manually simulate in the simulator:

Hardware -> Simulate Memory Warning

You can also simulate it programmatically:

- (void)simulateMemoryWarning
{
#if TARGET_IPHONE_SIMULATOR
  #ifdef DEBUG
    CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(),    (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
  #endif
#endif
}

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
like image 195
bryanmac Avatar answered Oct 20 '22 18:10

bryanmac