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

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

问题描述

我已经编程了很长时间,当我们看到的程序用完内存时,试图清理并退出,即正常失败。我不记得上次我看到一个人真的试图恢复并继续正常运行。

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天全站免登陆