brigadir
brigadir

Reputation: 6942

A way to send low memory warning to app on iPhone

I'm looking for some tool/app/tweak that can generate low memory warning on iPhone (jailbroken). Or, as alternative variant - tweak that simulates high memory usage.

I need it to test my app behavior on low memory warning.

Upvotes: 1

Views: 607

Answers (3)

stackich
stackich

Reputation: 5237

Swift:

UIApplication.shared.perform(Selector(("_performMemoryWarning")))

Upvotes: 0

Kjuly
Kjuly

Reputation: 35131

When you are running the app on simulator, you can do it by:

Hardware (on top menu) -> Simulate Memory Warning

And for real device you can do it with a private method:

[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];

Upvotes: 1

AliSoftware
AliSoftware

Reputation: 32681

  • You can test this on the Simulator, thru the "Simulate Memory Warning" menu item (from the "Hardware" menu)
  • On your device, you can call the private method _performMemoryWarning

    #if DEBUG
    [[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    #endif
    
  • Another solution is to send the notification manually too:

    CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
    

Upvotes: 3

Related Questions