UIKit< -segue-> SpriteKit内存泄漏

时间:2015-04-10 04:02:16

标签: ios swift

我喜欢Swift,iOS开发。

我在ViewController(用于UIKit)和ViewController(用于Spritekit)之间添加了一个Segue。

我运行iPhone模拟器,但内存导航器每个开关ViewController增加30M。

OSX 10.9.5,Xcode.6.1.1

  1. 新 - >项目 - >游戏
  2. 新 - >档案 - > Swift文件 - > FirstViewController.swift
  3. 将ViewController从库拖到故事板,设置自定义类:FirstViewController
  4. 将箭头设置为FirstViewController

  5. 选择FirstViewController,选项并拖动GameViewController(Segue)

  6. 设置标识符" toGame"
  7. 选择GameViewController,选项&拖动到自我退出
  8. 设置标识符"返回"
  9. 代码:

    class FirstViewController: UIViewController {
        @IBAction func returnMenu(segue: UIStoryboardSegue) {
            println("back!")
        }
    
        override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
            performSegueWithIdentifier("toGame", sender: nil)
        }
    }
    
    
    class GameViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
                scene.viewController = self
                skView.presentScene(scene)
            }
        }
    }
    
    class GameScene: SKScene {
    
        var viewController: UIViewController?
    
        override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
            for touch: AnyObject in touches {
            self.viewController?.performSegueWithIdentifier("back", sender: nil)
        }
    }
    

    感谢。

1 个答案:

答案 0 :(得分:0)

class GameScene: SKScene {
    weak var viewController: UIViewController?
}

谢谢大家! 弱参考! 内存泄漏解决了!