哪些操作系统将释放内存泄漏? [英] What Operating Systems Will Free The Memory Leaks?

查看:96
本文介绍了哪些操作系统将释放内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个桌面程序.大多数操作系统都在其自己的地址空间中运行该程序.

I've got a desktop program. Most Operating Systems run the program in its own address space.

当程序退出时,我相信大多数操作系统都会释放程序分配的内存,并将其返回到内存堆栈以供重用.

When the program exits, I believe most operating systems free the memory allocated by the program and return it to the memory stack for reuse.

我不确定该程序是否存在内存泄漏,是否还会将泄漏的"内存返回以供重用,还是在重新启动计算机之前丢失内存?

What I am not sure of, is if the program has a memory leak, will the memory "leaked" also be returned for reuse, or is it lost until the machine is rebooted?

这是我今天早些时候提出的问题的跟进:做小内存泄漏很重要,还有一些评论提到程序完成后会释放程序内存.如果在完成程序后释放了泄漏,那么对我来说,严格地消除程序中最小的泄漏肯定会给我带来更少的压力.

This is a followup to the question I asked earlier today: Do Small Memory Leaks Matter Anymore?, and a couple of comments there mentioned that program memory is freed when a program finishes. If leaks are freed when a program is done, then it definitely puts less pressure on me to rigorously rid my program of the tiniest leaks.

具体来说,我是Windows程序员,我需要知道Windows 98、2000,XP,Vista和7会发生什么(内存丢失或内存释放).但是我也想听听Mac和Windows上发生的情况. Unix机器.

Specifically, I'm a Windows programmer and I need to know what happens (memory lost or memory freed) for Windows 98, 2000, XP, Vista and 7. But I'd also like to hear what happens on Mac and Unix machines.

澄清:我说的是越来越多的泄漏.这些是恒定大小的泄漏,在程序运行时会发生一次.

Clarification: I am talking about non-growing leaks. These are leaks of a constant size that happen once when a program is run.

我确实意识到,程序中不断增加的泄漏非常严重,必须加以修复.

I do realize that leaks that are continually growing in a program are severe and must be fixed.

无论哪种方式,问题都不在于是否必须修复泄漏.程序结束时,是否由操作系统将泄漏的内存还给您.

Either way, the question isn't about whether or not leaks must be fixed. It is whether or not the Operating Systems give you back the leaked memory when the program ends.

推荐答案

内存泄漏只是指您的程序在分配内存时失去了对它的跟踪.操作系统仍然认为该内存在程序的地址空间中,因此在程序完成时将重新使用该内存.

A memory leak simply refers to when your program is allocating memory that it then loses track of. The operating system still considers this memory to be in the address space of the program, and thus it will be reused when the program finishes.

所有现代操作系统都使用一种称为虚拟内存的机制来跟踪程序内存.

All modern operating systems use a mechanism called virtual memory to keep track of a programs memory.

在这里,我非常详细地了解了虚拟内存

This is where I learned about virtual memory in quite good detail CS3231.

基本上,操作系统可以在其中将应用程序内存的块放置在物理内存中的任何位置,同时保持对这些块应指向的位置的映射.

Basically it is where the operating system can put chunks of an applications memory anywhere in physical memory, while maintaining a mapping to where these chunks should point to.

从应用程序的角度来看,它可以完全访问内存(在32位操作系统上为4gig,在64位操作系统上为大容量),并且即使物理内存小于或等于硬件限制,也可以继续分配直到达到硬件极限.此限制(这要求操作系统将某些内存内容存储在磁盘上,通常存储在交换文件中)

From the applications point of view, it gets full access to memory (4gig on 32-bit OS, something massive on 64-bit), and can keep allocating until it hits the hardware limit, even if physical memory is less than this limit (this requires the OS to store some of the contents of memory on disk, usually in a swap file)

这可以通过CPU上的硬件(通常称为MMU(内存管理单元)的模块)来实现,有时还可以使用TLB(转换后备缓冲区)来加速虚拟内存的运行.

This is facilitated by the hardware on the CPU, a module usually called the MMU (Memory Management Unit), and sometimes there is also a TLB (Translation Lookaside Buffer) to speed up virtual memory operations.

另一个页面详细说明了有关内存保护的内容,其中详细介绍了一些内部保护措施虚拟内存的工作原理.

Another page that explains a bit more about Memory Protection which details some more of the inner workings of Virtual Memory.

这篇关于哪些操作系统将释放内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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