iOS内存警告:如何"clean up as much memory as possible"?

iOS memory warning : how to "clean up as much memory as possible"?

收到内存警告时,将调用这些委托方法:

UIViewController中:

func didReceiveMemoryWarning()

Sent to the view controller when the app receives a memory warning.

AppDelegate中:

optional func applicationDidReceiveMemoryWarning(_ application: UIApplication)

Tells the delegate when the app receives a memory warning from the system. [...] Try to clean up as much memory as possible. next step is to terminate app

我的问题是,作为新手,我该如何"clean up as much memory as possible"?特别是如果我的应用程序中有一些泄漏。

感谢您的帮助

如果你有 material 泄漏,你应该 。随着您的前进,它们将成为问题的持久来源。 “调试内存图”工具在诊断这些问题时非常有用。

在回答这个问题时,当它说“尽可能多地清理内存”时,这意味着您应该释放任何可以很容易地重新检索或重新构造的东西。例如,也许您下载了图像并将它们保存在内存中。您可以从内存中删除这些图像,并在您再次需要它们时重新检索它们。