内存泄漏能够走多远? [英] How far can memory leaks go?

查看:64
本文介绍了内存泄漏能够走多远?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到的内存泄漏的许多倍。通常当我的malloc -ing像有没有明天,或叼着 FILE * 就像脏衣服。我一般假设(读:迫切希望)所有的内存清理程序终止至少当。有没有在那里泄漏的内存不会被回收时,该程序终止,或任何情况下崩溃?

I've run into memory leaks many times. Usually when I'm malloc-ing like there's no tomorrow, or dangling FILE *s like dirty laundry. I generally assume (read: hope desperately) that all memory is cleaned up at least when the program terminates. Are there any situations where leaked memory won't be collected when the program terminates, or crashes?

如果答案从语言到语言差别很大,那么让我们专注于C(++)。

If the answer varies widely from language-to-language, then let's focus on C(++).

请注意这句话的双曲使用,就像没有明天和晃来晃去......像脏衣服。不安全* 的malloc * ING可以伤害你爱的人。另外,请谨慎使用脏衣服。

Please note hyperbolic usage of the phrase, 'like there's no tomorrow', and 'dangling ... like dirty laundry'. Unsafe* malloc*ing can hurt the ones you love. Also, please use caution with dirty laundry.

推荐答案

没有。操作系统释放被持有过程的所有资源,当他们退出。

No. Operating systems free all resources held by processes when they exit.

这适用于操作系统维护的所有资源:内存,打开的文件,网络连接,窗口句柄...

This applies to all resources the operating system maintains: memory, open files, network connections, window handles...

这就是说,如果该程序的嵌入式系统上运行没有操作系统,或者用一个非常简单的或手推车操作系统中,存储器可能无法使用,直到重新启动。但如果你是在这种情况下,你可能就不会问这个问题。

That said, if the program is running on an embedded system without an operating system, or with a very simple or buggy operating system, the memory might be unusable until a reboot. But if you were in that situation you probably wouldn't be asking this question.

操作系统可能需要很长的时间,以释放某些资源。例如,一个网络服务器用于接受连接的TCP端口可能需要几分钟,成为免费的,即使通过正常程序关闭。的联网程序还可能持有的远程的资源,如数据库对象。远程系统应该释放这些资源时,网络连接丢失,但它可能需要更长的时间比本地操作系统。

The operating system may take a long time to free certain resources. For example the TCP port that a network server uses to accept connections may take minutes to become free, even if properly closed by the program. A networked program may also hold remote resources such as database objects. The remote system should free those resources when the network connection is lost, but it may take even longer than the local operating system.

这篇关于内存泄漏能够走多远?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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