是否“内存不足"一个可恢复的错误? [英] Is "Out Of Memory" A Recoverable Error?

查看:18
本文介绍了是否“内存不足"一个可恢复的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编程了很长时间,我看到的程序在内存不足时会尝试清理并退出,即优雅地失败.我不记得上次看到有人尝试恢复并继续正常运行是什么时候了.

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 I saw one actually attempt to recover and continue operating normally.

这么多处理依赖于能够成功分配内存,尤其是在垃圾收集语言中,似乎内存不足错误应该归类为不可恢复.(不可恢复的错误包括堆栈溢出等.)

So much processing relies on being able to successfully allocate memory, especially in garbage collected languages, it seems that out of memory errors should be classified as non-recoverable. (Non-recoverable errors include things like stack overflows.)

使它成为可恢复错误的令人信服的论据是什么?

What is the compelling argument for making it a recoverable error?

推荐答案

这实际上取决于您正在构建的内容.

It really depends on what you're building.

网络服务器在一个请求/响应对中失败但然后继续处理进一步的请求并非完全不合理.但是,您必须确保单个故障不会对全局状态产生不利影响 - 这将是一个棘手的问题.鉴于在大多数托管环境(例如 .NET 和 Java)中失败会导致异常,我怀疑如果在用户代码"中处理异常,它可以为未来的请求恢复 - 例如如果一个请求尝试分配 10GB 的内存但失败了,那应该不会损害系统的其余部分.但是,如果系统在尝试将请求移交给用户代码时内存不足,这种情况可能会更糟糕.

It's not entirely unreasonable for a webserver to fail one request/response pair but then keep on going for further requests. You'd have to be sure that the single failure didn't have detrimental effects on the global state, however - that would be the tricky bit. Given that a failure causes an exception in most managed environments (e.g. .NET and Java) I suspect that if the exception is handled in "user code" it would be recoverable for future requests - e.g. if one request tried to allocate 10GB of memory and failed, that shouldn't harm the rest of the system. If the system runs out of memory while trying to hand off the request to the user code, however - that kind of thing could be nastier.

这篇关于是否“内存不足"一个可恢复的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆