应用程序内存泄漏是否会导致操作系统内存泄漏? [英] Does an Application memory leak cause an Operating System memory leak?

查看:146
本文介绍了应用程序内存泄漏是否会导致操作系统内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们说程序泄漏内存时,在c ++中说一个 new 而没有 delete ,这真的 leak 吗?我的意思是,当程序结束时,是否仍将内存分配给某些未运行的程序并且无法使用,或者操作系统是否知道每个程序请求了什么内存,并在程序结束时将其释放?如果我多次运行该程序,是否会耗尽内存?

解决方案

在具有受保护内存的操作系统上(Mac OS 10+,所有Unix克隆,例如Linux,以及基于NT的Windows系统,意味着Windows 2000及更低版本),程序结束时释放内存.

如果您经常运行任何程序而又没有在两次运行之间将其关闭(同时运行越来越多的实例),则最终将耗尽内存,而不管是否存在内存泄漏,因此也是如此有内存泄漏的程序.显然,与没有内存泄漏的相同程序相比,内存泄漏的程序将更快地填充内存,但是在不填充内存的情况下可以运行多少次,很大程度上取决于程序正常运行所需的内存数量,而不是是否存在内存泄漏或内存泄漏.不是.除非您要比较两个完全相同的程序,一个程序有内存泄漏,另一个程序没有内存泄漏,那么这种比较实际上是不值得的.

当您的程序长时间运行时,内存泄漏变得最严重.典型的例子是服务器软件,例如Web服务器.例如,对于游戏,电子表格程序或文字处理器,内存泄漏并没有那么严重,因为您最终关闭了这些程序,从而释放了内存.但是,当然,内存泄漏是令人讨厌的小野兽,应从原则上加以解决.

但是如前所述,所有现代操作系统都在程序关闭时释放内存,因此即使内存泄漏,如果您继续打开和关闭程序,也不会填满内存.

When we say a program leaks memory, say a new without a delete in c++, does it really leak? I mean, when the program ends, is that memory still allocated to some non-running program and can't be used, or does the OS know what memory was requested by each program, and release it when the program ends? If I run that program a lot of times, will I run out of memory?

解决方案

On operating systems with protected memory (Mac OS 10+, all Unix-clones such as Linux, and NT-based Windows systems meaning Windows 2000 and younger), the memory gets released when the program ends.

If you run any program often enough without closing it in between (running more and more instances at the same time), you will eventually run out of memory, regardless of whether there is a memory leak or not, so that's also true of programs with memory leaks. Obviously, programs leaking memory will fill the memory faster than an identical program without memory leaks, but how many times you can run it without filling the memory depends much rather on how much memory that program needs for normal operation than whether there's a memory leak or not. That comparison is really not worth anything unless you are comparing two completely identical programs, one with a memory leak and one without.

Memory leaks become the most serious when you have a program running for a very long time. Classic examples of this is server software, such as web servers. With games or spreadsheet programs or word processors, for instance, memory leaks aren't nearly as serious because you close those programs eventually, freeing up the memory. But of course memory leaks are nasty little beasts which should always be tackled as a matter of principle.

But as stated earlier, all modern operating systems release the memory when the program closes, so even with a memory leak, you won't fill up the memory if you're continuously opening and closing the program.

这篇关于应用程序内存泄漏是否会导致操作系统内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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