SpriteKit TileMapNode MemoryLeak Bug

Hello community,


after days and days of researching and trying out my best, i do not find a solution on my memory leak problem.

I load my GameScene.sks with this code like everyone else does:


extension SKNode {

  1. class func unarchiveFromFile(file:String) -> SKNode? {
  2.   if let path = Bundle.main.path(forResource: file, ofType: "sks") {
  3.      let url = URL(fileURLWithPath: path)
  4.           do {
  5.              let sceneData = try Data(contentsOf: url, options: .mappedIfSafe)
  6.              let archiver = NSKeyedUnarchiver(forReadingWith: sceneData)
  7. archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
  8.              let scene = archiver.decodeObject(forKey: NSKeyedArchiveRootObjectKey)
  9.                   as! SKNode                        
  10.              archiver.finishDecoding()                   
  11.              return scene
  12.              }
  13.           catch { print(error.localizedDescription) return nil }
  14.     } else {
  15.        return nil
  16.     }
  17. }


and i am using it in my code here:


  1. func load(level: String) {
  2.      if let levelNode = SKNode.unarchiveFromFile(file: level) {
  3.      mapNode = levelNode
  4.      self.worldLayer.addChild(mapNode)
  5.      loadTileMap()
  6.      }
  7. }


If i comment out the line

self.worldLayer.addChild(mapNode)
everything works perfect and memory will never rise. But if i use it (i need it :D) memory keeps climbing and climbing.

With use of Instruments it says that the line with

let scene = archiver.decodeObject(forKey: NSKeyedArchiveRootObjectKey) as! SKNode
causes all the memory leaks.

Unfortunately i do not get it managed to remove my leaks.


I appreciate all help.

SpriteKit TileMapNode MemoryLeak Bug
 
 
Q