问题
I'm working on an app with a navigation controller. Swift + objective C
Important note: This freeze happens 100% when testing on iPhone 5c and never happens when testing on iPhone 6s
The scenario is:
- Go to TableViewController A
- Touch an item of the list to reach TableViewController B
- Go back to TVController A by pressing the top left arrow
- The app shows TableViewController A but freezes right away
The UI is frozen but the app is still running. If I press the Pause button (debug mode), I can see that the Thread 1 (Main thread) stack is:
0 semaphore_wait_trap
45 UIApplicationMain
46 main
47 start
I don't know where to start investigating so that I can find where the problem is.
Any ideas?
回答1:
After a day looking into it, I finally found out that it was linked to MKMapView deinit.
Later I found this post about a very similar topic:
WARNING: Output of vertex shader 'v_gradient' not read by fragment shader
According to - the god - @mojuba , who found that the freeze was also related to the deinit phase offered a fix for the DEBUG mode. Because this issue seems to happen only in DEBUG...
I successfully applied his fix to my code as followed:
deinit {
#if DEBUG
// Xcode8/iOS10 MKMapView bug workaround
if let mV = locationPickerView.mapView {
VControllerB.unusedObjects.append(mV) // addObject:_mapView];
}
#endif
}
NOTE that this produces a memory leak as mapView is never freed and kept within a static array of the VControllerB class.
NOTE 2: I reported the bug in Apple Bug Reporter while using Xcode 8.2.1 in Jan 27.
回答2:
This is a deadlock. Looks like you use dispatch_sync on main thread. To fix problem - check other threads. In some thread you will find the code that is waiting when dispatched block ends ...
来源:https://stackoverflow.com/questions/41869703/app-freezes-on-main-thread-on-iphone-5c-but-not-on-iphone-6s