Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit SKView showsFields memory usage

I am curious about when showsFields is turned on, the memory usage increase extremely fast? It can growth up to 500MB under 30 seconds. If my mac only have 8GB of RAM, I probably have less than 8 minutes to debug before memory warning, it will be worst when debug on real device.

The screenshot below is tested from a real device (iOS 9.2).

Memory Usage

You can quickly try it by creating a SpriteKit project and turn showsFields on in viewDidLoad() method inside the view controller.

skView.showsFields = true

If you want to see what showsFields does, place this snippet inside the scene's -didMoveToView(view:) method.

override func didMoveToView(view: SKView) {
    let myField = SKFieldNode.springField()
    myField.position = CGPointMake(frame.midX, frame.midY)
    myField.strength = 1.0
    self.addChild(myField)
}

Here is showsFields discussion from Apple

Discussion

When this debugging option is enabled, each time a frame is rendered, an image is drawn behind your scene that shows the effects of any physics fields contained in the scene.

like image 774
Kent Liau Avatar asked Jan 20 '16 15:01

Kent Liau


1 Answers

It looks like the debug image drawn per frame is not being cleared up properly which, is probably leading to this memory leak.

Best will to file a bug report with Apple via https://developer.apple.com/bug-reporting/ so they know multiple people are having this issue and can hopefully give a higher priority.

Hope that helps.

Kind regards, Mukund

like image 54
Mukund Agarwal Avatar answered Oct 24 '22 11:10

Mukund Agarwal