My app uses standard UINavigationViewController.
At some point, user has navigated to a ViewController which shows a SceneKit Scene.
This scene is very heavy in memory, since it has around 6000 geometries and each geometry has its own Material (this needs to be this way).
When user clicks the back button at the top bar in order to return to the previous viewController, the app correctly pops the current View Controller and shows the one below.
However, for around 4 seconds, the UI of the new ViewController shown freezes.
I have used Instruments Time Profiler, and I can see that big part of those 4 seconds are taken by these SceneKit methods:
-[NSConcreteMapTable countByEnumeratingWithState:objects:count:]
-[SCNMetalResourceManager _geometryWillDie:]
-[SCNMetalResourceManager _materialWillDie:]
It makes sense because there are so many geometries and materials.
How can I solve this situation, so that UI is not blocked while the heavy Scene is being released, either from a SceneKit perspective (making deallocation quicker) or from a UINavigationViewController perspective (maybe forcing deallocation of the Scene to happen in a separate thread?).