我在我的主包中使用属性列表来存储关于关卡和玩家的信息。第一次启动应用程序时,pList会被复制到手机中,然后根据需要从本地副本访问信息。我正在运行Instruments中的Leaks,我一直遇到内存泄漏,我认为这与创建存储在pList中的字典和其他数据类型有关。内存泄漏使用属性列表/ NSMutableDictionary
这里就是字典创建 - 寻找到plist中的路径后:
if fileManager.fileExists(atPath: path.path) {
if let dictionaryForPlist = NSMutableDictionary(contentsOf: path) {
return(dictionaryForPlist)
}
else {
print("pList not found")
}
let levelInstanceData = LevelData() //this class searches the main bundle for the plist and stores the pList as an NSMutableDictionary
let currentLevel = levelInstanceData.localDataFile["Level1"] as! Int //localDataFile is the NSMutableDictionary storing the information
let levelName = levelInstanceData.localDataFile["Level1Name"] as! String
我用力每一块数据转换为正确的数据类型,并用它在整个水平。
这里是仪器泄漏对象的屏幕截图。有没有其他人有这个问题,或有任何想法如何阻止泄漏?
有关于苹果SpriteKit论坛内存泄漏的几个问题。这是我用字典看到的第一个。你可能很幸运。第一个找到这个。 SK和错误.... – Confused