In addition to gnasher729's answer, iOS also has
a delegate method on UIViewController called didReceiveMemoryWarning().
Discussion
Your app never calls this method directly. Instead, this method is
called when the system determines that the amount of available memory
is low.
You can override this method to release any additional memory used by
your view controller. If you do, your implementation of this method
must call the super implementation at some point.
Unfortunately, 99% of the implementations I've seen are this default stub:
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
It's a bit of a tragedy of the commons scenario. Every app would benefit from implementing this behavior correctly (due to a lower chance of being force-stopped or paged to storage), but each app individually benefits from not implementing it (snappier response time, due to not needing to recompute/reload purged resources).