iOS开发:如何在设备上引发低内存警告? [英] iOS Development: How can I induce low memory warnings on device?

查看:369
本文介绍了iOS开发:如何在设备上引发低内存警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在低内存条件下测试我的应用程序功能,但很难测试。当应用程序在设备上而不是模拟器上运行时,如何在我的视图中引发触发didReceiveMemoryWarning方法的低内存警告?或者我可以在这些可能的条件下测试我的应用程序有哪些方法?

I'd like to test my app functions well in low memory conditions, but it's difficult to test. How can I induce low memory warnings that trigger the didReceiveMemoryWarning method in my views when the app is running on the device, not the simulator? Or what are some ways I can test my app under these possible conditions?

我无法使用模拟器的原因是我的应用程序使用游戏中心并邀请不在模拟器上工作。

The reason I can't use the simulator is my app uses Game Center and invites don't work on the simulator.

推荐答案

要在设备上进行测试,只需添加一些代码,定期分配大块内存而不释放它(即故意泄漏)。您可以在单独的线程中执行此操作,或者响应计时器,或使用最适合您测试和观察应用程序行为的任何机制。

To test on a device, just add some code that periodically allocates large chunks of memory without freeing it (i.e. leak on purpose). You can do this in a separate thread, or in response to a timer, or using whatever mechanism that best allows you to test and observe the behavior of your application.

您也可以选择创建一个单独的应用程序来执行类似的操作,并且设计为在后台运行,如果您想轻松地重复使用它和/或测试多个应用程序。

You might also choose to create a separate app that does something similar and is designed to run in the background, if you'd like to easily reuse this and/or test with multiple applications.

这篇关于iOS开发:如何在设备上引发低内存警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆