c ++程序结束时从内存释放指针? [英] are pointers released from memory when c++ program end?

查看:211
本文介绍了c ++程序结束时从内存释放指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个初学者的问题,但是我学习了使用c#进行编程,现在我正在使用c ++,并且现在我正在使用指针,我知道在处理完指针之后必须将它们从内存中释放出来,但是当程序已关闭,是将它们从内存中移出还是留在内存中?

This is a beginner question but I learned programming with c# and I am now moving to c++ and now that I am working with pointers, I know that I have to free them from memory when I'm done with them but when the program is closed are they removed from the memory or do they stay there?

推荐答案

程序结束时,它使用的所有内存(无论是否动态分配)都返回到操作系统.不管是C程序,C ++程序,C#程序还是您可能正在编写的任何其他类型的程序.

When your program ends, all the memory it used (whether dynamically allocated or not) is returned to the operating system. It doesn't matter if it's a C program, a C++ program, a C# program, or any other kind of program you might be writing.

现在,仅因为操作系统将回收内存,并不意味着您可以更轻松地进行内存管理.在程序运行时,您应尝试释放完成的所有内存.不这样做将导致内存泄漏",并且这些泄漏肯定会影响您的程序及其所运行的系统,至少在您的程序运行时.

Now, just because the OS will reclaim the memory doesn't mean you can be cavalier about memory management. While your program runs, you should try to take care of freeing any memory you're done with. Not doing so will cause "memory leaks", and those can certainly affect your program and the system it's running on, at least while your program is running.

这篇关于c ++程序结束时从内存释放指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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