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

查看:27
本文介绍了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?

我无法使用模拟器的原因是我的应用使用了 Game Center,并且邀请在模拟器上不起作用.

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天全站免登陆