_exit()的危险-内存泄漏? [英] dangers of _exit() - memory leak?

查看:88
本文介绍了_exit()的危险-内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,重复一个已经重复提出的问题,但是我找不到关于内存问题的具体提及.如果进程以_exit(0)或_Exit(0)终止,是否可以将其内存块丢失给OS? 谢谢, -nuun

Sorry to repeat a question that has been posed repeatedly, but i couldn't find a specific mention of memory issues. if a process terminates with _exit(0) or _Exit(0) can its memory block be lost to the OS? Thanks, -nuun

推荐答案

适用于几乎所有不会发生的消费者操作系统.现代多进程操作系统将在进程关闭时释放该进程可能获取的任何资源(内存,锁,打开文件等).因此,我一般认为,如果我只是在启动时就获取了内存或资源泄漏,则不算"为泄漏(而不是在运行时重复).

For just about any consumer O/S that will not happen. Modern multi-process Operating Systems will release any resources the process may have acquired (memory, locks, open files, etc) when the process shuts down. So I generally feel that memory or resource leaks "don't count" as leaks if I just acquire them at startup (not during runtime possibly repeatedly).

但是,仍然有很多嵌入式/实时平台不符合要求.如果您的程序可能在其中之一上运行,则应谨慎释放所获得的资源.但是即使在那儿,每次使用后重新启动设备通常也更容易...

However, there are still lots of embedded/realtime platforms out there for which that is not true. If your program might be run on one of those, you should be scrupulous about freeing up acquired resources. But even there it is often easier to just reboot the device after each use...

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

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