App freezes on main thread on iPhone 5c but not on iPhone 6s

人走茶凉 提交于 2019-12-08 01:48:40

问题


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:

  1. Go to TableViewController A
  2. Touch an item of the list to reach TableViewController B
  3. Go back to TVController A by pressing the top left arrow
  4. 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

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