Memory Leak for .showsPhysics

2019-04-23 09:20发布

问题:

I have just recently spent the past 5 hours trying to debug a memory leak in my Spritekit App.

After app Launch, I noticed a small climb in my memory usage.

I spent 3 of those 5 hours digging through reference material, learning about strong VS Weak with ARC (Definitely Recommend Reading up on that for Intermediates Such as myself)

Is anyone else experiencing this issue? If so is there any sort of explanation? Here is a small snippet of my GameViewController:

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = MainMenu(fileNamed:"MainMenu") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true
        skView.multipleTouchEnabled = true
        skView.showsPhysics = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .Fill

        //var GameSaveData = GameData()

        // Scene Config
        //scene.Landscape = "Test_Landscape"
        //scene.Area = "Start"

        skView.presentScene(scene)
    }else{

        print("Couldn't Load Game Scene")
    }
}

As you can see, I'm not doing anything out of the ordinary here. I would Post my gamescene code, but it was all commented out at the time I was still observing the memory leak.

回答1:

Eventually, out of fustration, I just started commenting lines of code, then building and profiling until the memory leak was solved.

Turns out in my GameViewController.swift file,

skView.showsPhysics = true

was the culprit. This must be somewhat of a new bug seeing as how I haven't seen this issue in < IOS 9.2



回答2:

skView.showsFPS = true
skView.showsNodeCount = true
skView.showsPhysics = true

Will leak memory by at least .3 MB/s.

Furthermore...

skView.showsFields = true

Leaks memory at a rate of 30-40 MB/s. Bad, Apple!