2

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.

Stack on main thread

Any ideas?

Mikael
  • 2,355
  • 1
  • 21
  • 45
  • are you loading bulk of data in view controller life cycle? – karthikeyan Jan 26 '17 at 08:54
  • not much no, only 3/4 items per list, memory doesn't even go high. – Mikael Jan 26 '17 at 09:01
  • Can you include the entire call stack. Frames 1 through 44? They can be shown by using the buttons in the filter field at the bottom of the Xcode window. – Mats Jan 26 '17 at 09:10
  • I re-run the app and I get the stack until 33 only now. It seems that the map contained in the VC B makes the app crashes when deallocating... – Mikael Jan 26 '17 at 09:41
  • some lines of source code of both VC A and B maybe could help. What contains VC B and what happens when VC B being deallocated? – carmine Jan 26 '17 at 09:47
  • 2
    You have a deadlock; the 5c doesn't have dual core while the 6s does. Do you have any `dispatch_sync` or similar? – Paulw11 Jan 26 '17 at 10:39
  • Investigating. I ll update the post when i find out. Thanks a lot – Mikael Jan 27 '17 at 01:02
  • What could be similar to a dispatch_sync? – Mikael Jan 27 '17 at 02:33
  • Ok, I found the source of the problem here but I don't know why it is happening yet. I have a var mapView:MKMapView? in my ViewControllerB and if I don't create it, I don't have any freezes. Also, I just add it to the view and set VControllerB as it's delegate.. Investigating... – Mikael Jan 27 '17 at 02:58
  • Other information: My MKMapView is inside a subview of VControllerB. I just create it in the subview init() – Mikael Jan 27 '17 at 07:02

2 Answers2

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.

Community
  • 1
  • 1
Mikael
  • 2,355
  • 1
  • 21
  • 45
0

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 ...

  • I added a breakpoint on all dispatch_sync within my program and the related Pods. none are triggered. – Mikael Jan 27 '17 at 02:29
  • No need to add breakpoints. When you reach deadlock state pause application. And then look what is going on in other threads. For [example](https://i.imgur.com/5I0hmQB.png) – Arkadi Tolkun Jan 27 '17 at 07:14