运行仪器时模拟内存警告?

发布于 2025-01-04 19:50:30 字数 83 浏览 2 评论 0原文

有办法做到这一点吗?如果是这样,如何以及可以在模拟器和/或真实设备中运行应用程序时完成吗?

是否有其他方法可以测试仪器中内存警告的响应?

Is there a way to do this? If so, how, and can it be done while running an app in the simulator and/or the real device?

Is there an alternative way to test response to memory warnings in Instruments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城花音 2025-01-11 19:50:30

据我所知,在设备上,出现内存警告的唯一方法实际上是创建内存不足的情况。您可以通过分配一大块内存并在几秒钟后释放它来做到这一点(无论如何不要忘记释放它)。
这可能看起来像黑客,但却是产生低内存条件的最可靠方法。

关于模拟器,您可能知道,在模拟器中运行应用程序时使用 Instruments 检查内存/性能问题并不完全可靠。无论如何,如果您想这样做,可以尝试发送此通知:

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

(来源

还请记住,模拟器具有“硬件/模拟内存警告”命令。

On the device, as far as I know, the only way to have a memory warning is actually creating a low memory condition. You can do that by allocating a big chunk of memory and freeing it after a few seconds (don't forget to release it, anyway).
This may appear like a hack, but is the most reliable way of producing a low memory condition.

About the simulator, as you possibly know, using Instruments to check for memory/performance issues while running your app within the simulator is not entirely reliable. Anyway, if you would like to do that, you can try sending this notification:

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

(Source)

Remember also that the simulator has got the "Hardware/Simulate Memory Warning" command.

谁的新欢旧爱 2025-01-11 19:50:30

您可以在运行 iPhone 模拟器时模拟内存警告,方法是转至菜单并选择:硬件 > 内存警告。模拟内存警告,即使在运行 Instruments 期间也可以随时完成。

You can simulate a memory warning while running the iPhone Simulator by going to the menu and selecting : Hardware > Simulate Memory Warning, which can be done at anytime even during running Instruments .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文