【发布时间】:2017-02-19 13:15:28
【问题描述】:
我在我的主包中使用一个属性列表来存储关卡和玩家的信息。第一次启动应用程序时,pList 会被复制到手机上,然后我会根据需要从该本地副本中访问信息。我在 Instruments 中运行 Leaks,并且不断遇到内存泄漏,我认为这与创建字典和存储在 pList 中的其他数据类型有关。
这里是创建字典的地方 - 在找到 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
我强制将每条数据转换为正确的数据类型,并在整个关卡中使用它。
这是 Instruments 中泄漏对象的屏幕截图。有没有其他人遇到过这个问题或有任何想法如何阻止泄漏?
【问题讨论】:
-
Apple SpriteKit 论坛上有几个关于内存泄漏的问题。这是我第一次看到字典。你可能很幸运。第一个找到这个。 SK 和错误....
标签: ios swift memory-leaks sprite-kit property-list