它是由程序员来释放退出()? [英] Is it up to the programmer to deallocate on exit()?

查看:82
本文介绍了它是由程序员来释放退出()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,当从它刚刚与退出键盘I输入错误的数据出口(1)

I have a program and when I input wrong data from the keyboard it just exits with exit(1).

我是用Valgrind的测试,虽然发生这种情况没有错误,但我可以看到,仍然有到达X字节。

I was testing with Valgrind and while this happens there are no errors, but I can see that there are still reachable x bytes.

所以我的问题:它是由程序员来释放内存撞上退出()或操作系统去照顾它之前?

So my question: Is it up to the programmer to free memory before hitting an exit() or is the OS going to take care of it?

推荐答案

在结束时,操作系统会照顾它(在每个现代操作系统,它不与旧版本的Windows的情况下)。你的程序(内存,打开的文件描述符,...)使用的每一个的ressource将在程序终止(除了一些资源,旨在生存进程终止,主要是一些共享内存/互斥体)操作系统被回收。

In the end, the OS will take care of it (on every modern OS, it was not the case with older version of Windows). Every ressource used by your program (memory, open file descriptors, ...) will be reclaimed by the OS when the program terminate (except some resource that are designed to survive process termination, mainly some sort of shared memory / mutex).

然而,的valgrind 在这里帮助您跟踪内存泄漏并报告一切可以利用的内存区域,这样就可以了,如果你愿意,手动释放它们。

However, valgrind is here to help you track memory leak and will report every available memory region so that you can, if you want, manually release them.

这篇关于它是由程序员来释放退出()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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