Should I dismiss a scene from going to another ViewController?

Hello.


I have an application with several tabs. As part of one tab, I have 3 SKScenes with some animation within. I also have an option to present another UIViewController modally. This other VC has another SKScene. I noticed that when I go from one VC to another, my frames drop significantly after a few iterations.


Do I need to dismiss the first three SKScenes before moving to another ViewController and vice versa?


Should I just use removeFromParent()?


Thank you!

Replies

Try pausing the scenes that are not visible. However, they're probably still going to be contending for FPU resources (texture storage, etc), so it'd probably be most efficient to shut down and release all scenes other than the one that's visible.


(However, it's hard to make sure you don't leak the other scenes due to memory reference cycles. You might have to spend a bit of effort in Instruments to make sure that they really go away.)

I replaced my second SKScene with CoreGraphics but it still does not address the issue. There is definitely memory leak every time I go to another ViewController. Searching on Internet did not reveal any workable solution.


The following:


@IBAction func goToWindVC(sender: UIBarButtonItem)
    {
        self.spriteViewDep?.removeFromSuperview()
        self.spriteViewDep = nil
        performSegueWithIdentifier("segueWind", sender: self)
    }


gives the following error:


/BuildRoot/Library/Caches/com.apple.xbs/Sources/Metal/Metal-55.1.1/Framework/MTLTexture.m:643: failed assertion `MTLTextureDescriptor has one or more dimensions set that are zero or greater than the maximum allowed size.'


perhaps due to the Auto Layout, avoiding which is not an option.


Has anyone managed to implement it?


EDIT:


Looks like I just had to implement the following in the viewWillAppear to solve it:


if self.spriteViewDep == nil
        {
               ... // Create scene
        }


Do not see memory leak anymore.


Thanks a lot!