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

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

问题描述

很抱歉重复一个反复提出的问题,但我找不到具体提到的内存问题.如果进程以 _exit(0) 或 _Exit(0) 终止,它的内存块是否会丢失给操作系统?谢谢,-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

推荐答案

适用于几乎所有不会发生的消费者 O/S.现代多进程操作系统将在进程关闭时释放进程可能获得的任何资源(内存、锁、打开的文件等).所以我通常觉得,如果我只是在启动时获取它们(而不是在运行时可能重复),那么内存或资源泄漏不算"为泄漏.

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