Is “Out Of Memory” A Recoverable Error?

后端 未结 24 2096
闹比i
闹比i 2020-11-30 21:44

I\'ve been programming a long time, and the programs I see, when they run out of memory, attempt to clean up and exit, i.e. fail gracefully. I can\'t remember the last time

24条回答
  •  长情又很酷
    2020-11-30 22:21

    I'm working on SpiderMonkey, the JavaScript VM used in Firefox (and gnome and a few others). When you're out of memory, you may want to do any of the following things:

    1. Run the garbage-collector. We don't run the garbage-collector all the time, as it would kill performance and battery, so by the time you're reaching out of memory error, some garbage may have accumulated.
    2. Free memory. For instance, get rid of some of the in-memory cache.
    3. Kill or postpone non-essential tasks. For instance, unload some tabs that haven't be used in a long time from memory.
    4. Log things to help the developer troubleshoot the out-of-memory error.
    5. Display a semi-nice error message to let the user know what's going on.
    6. ...

    So yes, there are many reasons to handle out-of-memory errors manually!

提交回复
热议问题