如果我在使用新的和结束的程序分配数据后没有调用删除运算符,会发生什么?
如果我在使用 new 分配数据后没有调用删除运算符会发生什么情况。 我知道已分配的数据在释放之前不会可用,但是在结束程序后?
为什么电脑看起来很恶心xD,我的意思是它很慢,但一段时间后它的性能变得更好,但不像程序执行之前那样?
注意:我运行的是Windows XP。
What happens if I didn't call delete operator after allocating data using new.
I know that the data that has been allocatted, won't be available until releasing it, but after ending the program ?
Why the PC seems to have nausea xD, i mean that it is very slow but after a while its performance become better but not like before the program execution ?
Note: I'm running windows XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当程序结束时,它请求的所有内存(堆栈,堆等等)都被操作系统占用。
When the program ends all the memory it requested (stack, heap whatever) is claimed by the operating system.
我认为您正在看到将有用的程序从主内存逐出到磁盘的效果。
您的故意泄漏程序正在尝试分配系统上的所有内存。为了满足您的程序的需求,Windows 会查找系统上的其他程序,将其内存写入页面文件,并将其内存重新分配给您的程序。当您看到页面文件使用量跃升至最大值时,这是因为大多数其他程序已被推到那里而不是主内存。
当您的程序退出时,Windows 会回收该程序的所有内存(如其他人所述)。但是计算机上的所有其他程序的内存仍然保存在磁盘上的页面文件中,而不是主内存中。因此,当它们运行时,Windows必须从磁盘加载它们的内存页面,使得程序显得很慢。一段时间后,程序将移回主内存,性能看起来会正常。
I think you're seeing the effects of evicting useful programs from main memory to the disk.
Your intentionally-leaky program is trying to allocate all memory on the system. To satisfy your program's demand, Windows is finding other programs on the system, writing their memory to the page file, and reallocating their memory to your program. When you see the page file usage jump to maximum, it's because most other programs have been shoved there instead of main memory.
When your program exits, Windows reclaims all the program's memory (as noted by others). But all the other programs on your computer still have their memory saved in the page file on disk, not in main memory. So when they run, Windows has to go load their memory pages from disk, making the program appear slow. After a while, the programs will move back to main memory, and performance will look like normal.
假设您编写了自己版本的“ls”命令,并且内存管理非常糟糕,以至于每次运行都会泄漏 10 MB,这是一个很大的泄漏。这有关系吗?并不真地。当程序退出时,系统将回收所有内存,这很可能是在程序启动后的几分之一秒内。当然,你的自尊心会受到影响,工艺水平也会降低,但系统不会受到影响。用户很可能永远不会知道内存管理得有多糟糕。
现在假设您编写了自己的 Apache 版本。它预计一次运行数月而不重新启动,因此即使泄漏少量内存,随着时间的推移也会累积并导致问题。用户可能会知道这一点。系统管理员当然会的。
总而言之,操作系统做了正确的事情并回收了内存。泄漏的软件是不好的。但在某些情况下,这并不重要。
Suppose you wrote your own version of the 'ls' command, and the memory management was so poor that it leaked 10 MB every time it ran, which is a large leak. Does this matter? Not really. The system will reclaim all memory when the program exits, which is most likely a fraction of a second after it starts. Sure, your pride is affected, and the craftsmanship would be low, but the system doesn't suffer. It is likely the user would never know how poorly the memory is managed.
Now suppose you wrote your own version of Apache. It is expected to run for months at a time without restart, so even if it leaked a small amount of memory, that would accumulate over time and cause a problem. The user would likely know about this one. The sysadmins certainly would.
So to summarize, the OS does the right thing and reclaims memory. Leaky software is bad. But there are cases where it doesn't matter much.
当程序结束时,程序分配但未能释放的所有内存都会自动释放。也就是说,程序完成后不再对操作系统产生任何影响。
All the memory your program allocated, but failed to release, is automatically released when your program ends. That is, after your program finishes it no longer has any effect or influence on the OS.
堆和栈内存被分配给每个进程。动态分配发生在堆上。每个可执行文件或程序都在一个进程中运行。因此,一旦程序结束,为该进程分配的堆和堆栈就会返回给操作系统。这包括泄漏的动态内存。
一旦程序结束,它就不应该对操作系统的性能产生影响。
The heap and the stack memory are allocated to each process. Dynamic allocations happen on the heap. Each executable or program runs in a process. So once the program ends the heap and the stack allocated for that process are returned back to the OS. This includes the leaking dynamic memory.
Once the program has ended, It should have no bearing on performance of the OS.
内存本身不是问题,会自动回收。
它是由于对象析构函数没有被整齐地调用而被持有的其他资源(因为您没有删除内存,所以析构函数没有被调用)。关闭这些资源。
简单的例子是:
The memory itself is not a problem this will be re-claimed automatically.
Its the other resources that are held because object destructors are not called to tidily (because you did not delete the memory the destructor(s) are not called). close these resources.
Simple examples are: