内存泄漏和其他资源的过程后死亡 [英] Memory leaks and other resources after a process dies

查看:84
本文介绍了内存泄漏和其他资源的过程后死亡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个程序有内存泄漏。

Suppose a program has memory leaks.

1)当一个进程死亡(正常或段故障),是那些泄漏的内存释放?

1) When a process dies (normally or segmentation fault), are those leaked memory freed?

2)什么其他资源进程持有?

推荐答案

栈和堆内存被释放,文件描述符都是现代系统关闭,我想。

Stack and heap memory is freed and file descriptors are closed on all modern system, I think.

在POSIX系统中,有许多资源未释放时,一个进程退出,共享的信号,消息队列和内存段。这些都意味着是进程之间持久的,所以他们根本无法。它是应用程序的责任,让他们自由。

On POSIX systems there are a number of resources that are not freed when a process exits, shared semaphores, message queues and memory segments. These are meant to be persistent between processes, so they simply can't. It is the responsibility of the application to free them.

这可能做到这一点与例如 ON_EXIT 处理,但通常有一种简单的方法。对于内存段,你会通常使用 shm_unlink 的所有进程都开这样的后段。段则不再存在时,最后一个进程(及其文件描述符的段)被关闭。

It could do that e.g with on_exit handlers, but usually there is a simpler way. For memory segments you would typically use shm_unlink after all processes have opened such a segment. The segment then ceases to exist when the last process (and its file descriptor to the segment) is closed.

这篇关于内存泄漏和其他资源的过程后死亡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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