My app freezes but no error appears

╄→гoц情女王★ 提交于 2019-12-17 23:15:25

问题


Does any body know what I have to check if my app freezes? I mean, I can see the app in the iPad screen but no buttons respond. I have tried debugging the code when I click on the button, but I haven't seen anything yet. I was reading about the Instruments tools; specifically how do I use them?

Can anybody help me? I just need an explanation about how use the tools.


回答1:


It sounds like you've blocked the main thread somehow. To debug, run the app in the debugger and when the app freezes, hit the pause button above the log area at the bottom of Xcode. Then on the left side, you'll be able to see exactly what each thread is doing, and you can see where it's getting stuck.

Probably either a long loop on the main thread or a sync deadlock.




回答2:


Top answer is correct. You can debug this with "Pause" option. Most common way to block main thread is to call dispatch_sync on the same thread you dispatching. Sometimes you call same code from dispatch_once.




回答3:


Besides pausing and following the stacktrace I think as an additional thing to do, is to check in the code if there's any loop causing the app freezes.

I recently ran into a similar problem, but stack trace didn't help much, I figured out that I was having an eternal loop when calling a reloadData() inside layoutsubviews method and that was causing a freeze with no errors and no help from instruments.




回答4:


I have similar case in my project and the reason was another developer who added setNeedsLayout() inside method layoutSubviews() and this make infinite loop and freeze the app.



来源:https://stackoverflow.com/questions/10196344/my-app-freezes-but-no-error-appears

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