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 {
class func unarchiveFromFile(file:String) -> SKNode? {
if let path = Bundle.main.path(forResource: file, ofType: "sks") {
let url = URL(fileURLWithPath: path)
do {
let sceneData = try Data(contentsOf: url, options: .mappedIfSafe)
let archiver = NSKeyedUnarchiver(forReadingWith: sceneData)
- archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObject(forKey: NSKeyedArchiveRootObjectKey)
as! SKNode
archiver.finishDecoding()
return scene
}
catch { print(error.localizedDescription) return nil }
} else {
return nil
}
}
and i am using it in my code here:
func load(level: String) {
if let levelNode = SKNode.unarchiveFromFile(file: level) {
mapNode = levelNode
self.worldLayer.addChild(mapNode)
loadTileMap()
}
}
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.