9.2 Memory leak - skView.showsPhysics = true

Radar filed: 23818104

Steps to recreate.

1. New SpriteKit Project

2. In GameScene.swift add protocol SKPhysicsContactDelegate

3. Add following lines to didMovetoView

physicsWorld.contactDelegate = self /

physicsBody = SKPhysicsBody(edgeLoopFromRect: scene!.frame)

4. In GameViewController viewDidLoad set skView.showsPhysics = true


Every second memory usage goes up by 0.1 MB until the app crashes


In a multi scene app the leak continues across transitions, so it seems to related to the view controller, rather than the SpriteKit scene

Replies

Wow... thanks for pointing this out. I had seen the memory usage skyrocketing in my app, and spent a fair bit of time profiling to see what the heck was causing it. I just confirmed that it's the skView.showsPhysics flag. I have a debug menu that allows me to toggle that on and off, and I can see it immediately when toggling it on.

Hi MacMacMac,


Thank you for reporting this. This is a valid issue and will be addressed in a future software update.

Note that this issue is constrained to the physics visualization should not have any impact on normal use of SpriteKit physics.


Thanks,


-Tim

Hey Tim,


Thanks for responding and letting us know that it will be addressed.


Hopefully this post will save someone the couple of hours I spent trying find the bug in my code.

Hi all

I'm not sure if this helps but my app ran fine under 9.1 but under 9.2 major memory leak found and it traces back to showfields=true

verified, just found it myself and came to report

Thank you for posting and reporting this.


I have been mashing on my spritekit code for three days trying to stop the memory bleed. I thought it was me. After reading this post I decided to make a default File -> New -> Project... iOS -> Application -> Game in Xcode Version 7.3 (7D175) and see what happens when I run it. For me, running the default file (adding nothing nor making any changes) on the iPhone 6s simulator 9.3 and 'touching' the screen once to get one spinning spaceship, the memory increases by 0.1MB every couple of minutes. It started out with 65.4MB and it increased to 66.3 very soon. After about thirty seconds it was 66.4MB. I watched it for about ten minutes when it reached 67.7M, so I went to get some coffee.


I have come to realize that I cannot stop this creep up in MB usage and will not panic as long as I keep it to a minimum.