4

I want to test out my app in low memory conditions. Previously my approach to this was running

[NSTimer scheduledTimerWithTimeInterval:2.0 target:[UIApplication sharedApplication] selector:@selector(_performMemoryWarning) userInfo:nil repeats:YES];

but it does not work anymore. And by working I mean the didReceiveMemoryWarning is not called. I've also tried:

 [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object: [UIApplication sharedApplication]]; 
 [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object: nil];
 [[UIApplication sharedApplication] _performMemoryWarning];

But none of the above seem to work.

Any ideas would be appreciated

TompaLompa
  • 949
  • 6
  • 17
  • 1
    If it doesn't even work when you use the simulator hardware menu (as you suggest in your comment on the answer) then it's more likely that the problem is in your function. Which class isn't receiving the method? When did it stop working? Have you overridden the method and not called super? – jrturton Jan 23 '13 at 08:07
  • I have overridden the method and I have called super. As you say the class(es) does not receive the call. – TompaLompa Jan 23 '13 at 08:22
  • Seems like a backgroundView caught it – TompaLompa Jan 23 '13 at 10:15

2 Answers2

1

Look at this post Is there a way to send Memory Warning to iPhone device manually?

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

In simulator:

Hardware -> Simulate Memory Warning

Community
  • 1
  • 1
Mikhail
  • 4,271
  • 3
  • 27
  • 39
0

An easy way to test memory warning code is to build to the simulator and click on

Hardware ==> Simulate Memory Warning

WolfLink
  • 3,308
  • 2
  • 26
  • 44