向 iPhone 上的应用程序发送内存不足警告的方法

问题描述 投票:0回答:3

我正在寻找一些可以在iPhone(越狱)上生成低内存警告的工具/应用程序/调整。或者,作为替代变体 - 模拟高内存使用量的调整。

我需要它来测试我的应用程序在内存不足警告时的行为。

ios iphone memory-leaks low-memory
3个回答
3
投票
  • 您可以通过“模拟内存警告”菜单项(来自“硬件”菜单)在模拟器上进行测试
  • 在您的设备上,您可以调用私有方法

    _performMemoryWarning

    #if DEBUG
    [[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    #endif
    
  • 另一种解决方案是手动发送通知:

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

1
投票

当您在模拟器上运行应用程序时,您可以通过以下方式完成:

硬件(顶部菜单)-> 模拟内存警告

对于真实设备,您可以使用私有方法来完成:

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

0
投票

迅速:

UIApplication.shared.perform(Selector(("_performMemoryWarning")))
© www.soinside.com 2019 - 2024. All rights reserved.