4

When a system is running low on available memory can it ask programs in general to give up any non-vital memory without shutting down. Like a process signal which causes the processes to yield any memory they can which does not render them unusable.

Think of it as a stage before caching them to disk or terminating them altogether.

Any Operating systems that do this?

2
  • BTW: there are just so many Operating Systems (or Programming Languages or Virtual Machines or Libraries or …) that the question "is there any OS that does this" is pretty meaningless, since the answer is almost always going to be "Yes". Among the tens of thousands of OSs, you can be pretty sure that everything which is possible or thinkable has been done, just by pure statistics. Commented Sep 18, 2018 at 20:59
  • Windows has a "high memory" event. Commented Sep 19, 2018 at 12:15

2 Answers 2

2

iOS does. First, it will ask apps to give up memory when it gets tight (and apps that give up memory when needed tend to live longer), and there is a class (I think) NSCache which contains cached objects that can disappear any time. MacOS 9 did similar things. On MacOS X the assumption is that there is unlimited memory.

2
  • Linux and Android do it too (In different ways. Android uses a custom Out of Memory killer). Feel free to look it up and add it to your answer. Commented Sep 18, 2018 at 21:59
  • @RubberDuck Android straight up Kills process when Out of memory , I'm asking about giving a signal of sorts to allow applications to release some memory on their own Commented Sep 21, 2018 at 12:57
0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.