Tag: 收到了记忆警告

如何在Swift中实现didReceiveMemoryWarning?

每当我创build一个新的视图控制器子类,Xcode自动添加该方法 override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated } 通常我只是删除它或忽略它。 这也是我见过的所有教程都做的。 但我认为,既然Xcode每次都给我,应该有点重要吧? 我应该在这里做什么? 我认为,处理资源意味着把它们设置为零,但究竟是“可以重新创build的资源”呢? 我看到了这些问题: 如何实现didReceiveMemoryWarning? UIViewController在ARC环境中的didReceiveMemoryWarning iPhone开发 – 模拟内存警告 但他们都是斯威夫特之前的。 虽然我对Objective-C不太了解,但我听说内存pipe理是不同的。 这是如何影响我应该在didReceiveMemoryWarning做什么? 其他说明: 我模糊地意识到自动引用计数和懒惰的实例化 关于didReceiveMemoryWarning的文档 ,我发现是相当简短的。