dub
dub

Reputation: 491

SpriteKit Memory increase every time new scene presented

I am trying to solve an issue where SpriteKit is causing memory leakage every time I re-open a scene after dismissing it and it's view controller. This is the upwards trend every time it's opened: spritekit memory leak

When I check instruments, the issue appears to be with the SKTileMapNode "SKCTileMapNode::_ensureChunkForTileIndex(unsigned int)" but I am using this code upon willMove(from view: SKView):

 for child in children {
        if child.isKind(of: SKTileMapNode.self) {
            (child as! SKTileMapNode).fill(with: nil)
            print("Wiped tiles for tilemaps")
            child.removeAllActions()
            child.removeFromParent()
        } else if child.isKind(of: SKSpriteNode.self) {
            (child as! SKSpriteNode).texture = nil
            child.removeAllActions()
            child.removeFromParent()
            print("Wiped SKSpriteKitNodes")
        } else {
            print("Other child removed")
            child.removeAllActions()
            child.removeFromParent()
        }

    }

And as you can see from the image above, the result is still upwards of memory usage. Still with the SKTileMapNode in instruments?

Upvotes: 1

Views: 259

Answers (1)

dub
dub

Reputation: 491

I tried checking if things had not been deallocated and this did not solve the problem. I used a developer technical support ticket and an engineer advised me to turn off "GPU Frame Capture" in the scheme for the project.

This 95% solved the problem. Memory usage has reduced to a lot more reasonable amount and the app no longer continues to build up memory usage after I implement reasonable methods to deallocate scenes, nodes etc...

I asked if this solution was only for testing in Xcode and I was told it was not, this is how my app will perform on the App Store:

"GPU Frame Capture is a tool for debugging and is only present when running your app with the Xcode Debugger attached!" - Said the engineer.

Upvotes: 3

Related Questions