子进程中的内存泄漏怎么办
我在unix平台上。
存在 memleak 的进程的内存会在进程终止时被清理。
如果一个进程已经产生了一个子进程,而该子进程存在内存泄漏,那么情况又如何呢? 子进程终止时泄漏的内存会被清除吗?或者这个内存现在会保留在父进程中吗?
谢谢
Im on unix platform.
The memory of a process with a memleak is cleaned at process termination.
What about a process, that has spawned a child, where the child has a memleak.
Will the leaked memory be cleaned up at childprocess termination? Or will this memory now stick with the parent process.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
子进程分配的内存仅存在于子进程的虚拟地址空间中,而不存在于父进程的虚拟地址空间中。一旦子进程终止或通过 exec 系列函数之一将其自身替换为新的程序映像,它将被释放。
这与线程形成对比,线程共享公共虚拟地址空间,并且在新线程中进行的分配将在线程退出后持续存在并仍然可供其他线程使用。
The memory allocated by the child process exists only in the child process's virtual address space, not the parent's. It will be freed as soon as the child process terminates or replaces itself with a new program image via one of the
exec
family of functions.This is in contrast to threads, which share a common virtual address space, and where allocations made in a new thread will persist after the thread exits and remain usable by other threads.