为什么内存泄漏这么严重? [英] Why is memory leak so bad?

查看:53
本文介绍了为什么内存泄漏这么严重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道内存泄漏很糟糕,我应该总是释放动态分配的内存,而内存泄漏是不好的做法.我的问题是为什么内存泄漏在当今具有大 RAM 的现代操作系统中被认为如此糟糕.我的意思是小的内存泄漏(可能小于 1 MB)而不是一些消耗大量内存的真正大的结构.

I know memory leak is bad and I should always free dynamically allocated memory, and having memory leak is bad practice. My question is why memory leak considered so bad in todays modern operating system with large RAM. I mean to small memory leaks (maybe less than one MB) and not of some really big structures that consume a lot of memory.

推荐答案

内存泄漏很糟糕,因为您的程序会要求资源并在其整个生命周期内保持它们被占用,即使它不再需要它们.如果你在程序启动时有一个大小为 X 的静态泄漏并且它不会随着时间的推移而增长,那很不幸,但可能不是世界末日.如果每次执行 Y 时都有泄漏,那就是一个更大的问题,因为程序的内存消耗会继续增长,最终会占用不合理的资源量.

Memory leaks are bad because your program claims resources and keeps them occupied for its entire lifecycle, even though it does not need them anymore. If you have a static leak the size of X when the program starts and it does not grow over time it's unfortunate, but probably not the end of the world. If you have a leak every time you perform Y, it's a much bigger problem, as the program's memory consumption will continue growing and will eventually take up an unreasonable amount of resources.

这篇关于为什么内存泄漏这么严重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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