How to test memory low condition on real iphone/ipad device (not simulator)?

喜你入骨 提交于 2019-12-09 12:46:08

问题


I know that there is a "Simulate Memory Warning" on the simulator. However, many people said that the app should be test on real device. How can I test the memory low condition on real device? Running as many apps as possible in background? Any better way?

Thanks.


回答1:


You can use private API to send low memory message:

[[UIApplication sharedApplication] _performMemoryWarning];

Though remember to remove from release otherwise your app might get rejected ;)

Kudos goes to: http://forum.148apps.com/showpost.php?p=8603&postcount=3




回答2:


The previous answer doesn't compile on my machine. The workaround is to call performSelector:, like this:

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



回答3:


There are a few tricks you can try:

Put some NSLog statements in your low memory delegate calls to see if your app is getting stress tested in normal use.

If not:

Prior to running your app, start several large slow web sites downloading in Safari; then while testing your app, send some large emails to a push account on your test device.

For stress testing purpose (use a preprocessor define that is NOT in your distribution build), malloc an extra 10 or 20 or some-test-number megabytes that your app doesn't need, write into it some junk/rand() data to dirty the pages, and don't release it (you can purposely leak 25MB for max stress).

You can also create your own test background app, say a music player that plays silence, put it in the background before testing your app, and have the background audio callback allocate and dirty some large chunks of data.



来源:https://stackoverflow.com/questions/4200936/how-to-test-memory-low-condition-on-real-iphone-ipad-device-not-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!