所以,我最近注意到,在完成某个项目的开发后,我们的开发服务器在 4GB 内存中稳定地剩余 ~300MB。假设这是由于开发阶段的内存泄漏,内存最终会自行释放还是需要重启服务器。将来是否有任何工具可用于防止这种情况发生(除了显而易见的“不要编写产生内存泄漏的代码”之外)?有时它们会消失一段时间,随着时间的推移,我猜它们会随着您继续测试您的应用而累积起来。
最佳答案
您运行的是什么操作系统?现在大多数操作系统都会在进程退出时清理进程的泄漏内存。您看到的正在使用的内存可能实际上被用于文件系统缓存。这没什么好担心的——操作系统会在必要时回收此内存。
发件人:http://learnlinux.tsf.org.za/courses/build/internals/ch05.html
The amount of free memory indicated by the free command includes the current size of the buffer cache in its calculation. This is misleading, as the amount of free memory indicated will often be very low, as the buffer cache soon fills most of user memory. Don't' panic. Applications are probably not crowding your RAM; it is merely the buffer cache that is taking up all available space. The buffer cache counts as memory space available for application use (remembering that it will be shrunk as required), so subtract the size of the buffer cache to see the real amount of free memory available for application use
关于c - 开发过程中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1676593/