40

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.

jscs
  • 63,694
  • 13
  • 151
  • 195
Vanjo
  • 551
  • 1
  • 5
  • 9
  • Please how to solve this problem. Can you give any clues. – Ranjithkumar Jan 04 '17 at 15:58
  • 1
    Do exactly as Ben Baron suggests. Look at the left hand slide of Xcode after pausing and identify the functions/ threads that may be blocking the UI. Comment out each function at a time and rerun the project. You will then be able to identify which is causing the app to freeze. – Ahmed Khedr May 09 '18 at 10:19

6 Answers6

115

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.

pause button

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

Sebastian Hojas
  • 4,158
  • 2
  • 27
  • 38
Ben Baron
  • 14,496
  • 12
  • 55
  • 65
  • 1
    Hi man! but which instrument should i use. Allocations, Leaks, Activity Monitor, this is the first time that i tried to use Instruments, i don't know how use it... About your possible answer i guess your'e probably right. because when i click the button, i call a pop over and show another view at the same time, the pop over has its own connection to web service and the view controller has another... – Vanjo Apr 17 '12 at 18:58
  • 7
    You don't use any of the instruments, just Xcode. Run your app by clicking the run button in the top left of Xcode. That will run in in the debugger. Navigate in your app until you reproduce the freeze. Then click the little pause button (looks like `||`) just above the log output area at the bottom. It's toward the left hand side in the bar just above the log area. Once you pause it, you'll see all of your thread stack traces on the left and you can see what method it's stuck on. – Ben Baron Apr 17 '12 at 20:16
  • 1
    Also, are you using synchronous or asynchronous connections to that web service? You should not use synchronous (blocking) network connections on the main thread. – Ben Baron Apr 17 '12 at 20:17
  • Thanks a lot man, i guess i found the possible error. It was not the app. i don't know if you have listened something about light streamer with push technology or some thing like that. in the app are installed some libraries for making work it, but when i click on the button, light streamer events doesn't respond because it have a loop until the connection return, it is probably that the connection with server are missing, that is the reason because my app stop exactly in that part. i had problems with my network connection. – Vanjo Apr 17 '12 at 21:07
  • I have not used that, but it sounds like that library is thread blocking and should not be used in the main thread. Even if the server is up, if there is a delay in the response it would freeze your user interface. – Ben Baron Apr 17 '12 at 21:22
  • yeap that's exactly what it is going to happen if some delay occurred. You won't see that delay but in my case i was blocked for the router. – Vanjo Apr 17 '12 at 21:37
  • 1
    Thank you, in my case there was an ugly mutex lock on my third party audio engine – masaldana2 Jul 02 '19 at 04:07
3

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.

Timur Bernikovich
  • 5,660
  • 4
  • 45
  • 58
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.

RBT
  • 24,161
  • 21
  • 159
  • 240
sheinix
  • 167
  • 1
  • 13
1

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.

0

The same Issue Happened to me with ios 13.4 and then I tried the above solution but it doesn't solve it. so I had one element with break constraint on the storyboard. So after resolving the constraint it solve the problem.

Anubhav
  • 41
  • 4
  • 1
    Welcome @anubhav verma on StackOverflow, It would be really helpful if you add some code or steps to resolve the issue. For more help please visit https://stackoverflow.com/help/how-to-answer – Rajan Apr 22 '20 at 06:37
0

I suggest checking your sizes especially in collection views if they are not fitted they will freeze your app and also check your constraints

jamal zare
  • 1,037
  • 12
  • 13