English 中文(简体)
在有活力的记忆分配中,在方案终止后,一个忘却去找记忆,这种记忆是否会被分配?
原标题:In dynamic memory allocation, after the program terminates and one forgets to deallocate the memory, will that memory stay allocated?
  • 时间:2012-05-19 10:07:21
  •  标签:
  • c++
  • dynamic

阅读C++书,但我看不到答案。 我知道的是充满活力的记忆分配,例如当我行使职能时:

void memoryleak(){
int * ptr = new int; 
}

但是,由于点名是局部变量,加上记忆线的点名被分配,因为它静态,因此所分配的记忆被丢失,不能再用于方案。

But does it mean the memory is lost forever or only until the program is terminated like after compiling this code snippet:

main(){
int * ptr = new int; 
}

在方案终止后,是否保留或分配记忆? 如果中止分配,重新启动常设仲裁法院是否将所有旧的记忆重新定位。 还有一个问题,即从奇怪的角度来看,它们(在分配中)使用的记忆是什么?

最佳回答

在方案终止时,本组织将恢复所分配的所有记忆。 你在方案期间透露的任何记忆,一旦方案终止,就会归还给现有的记忆库。

当你用<代码>新分配记忆时 然后由<代码>RAM予以支持。 如果你分配的记忆比现在多,那么该计算机就可以在磁盘上使用一个交换文件。

问题回答

答案取决于你要求的人。 就C++语言而言,记忆刚刚消失。 找不到退路。

但是,任何合理的职业顾问都很聪明,可以知道分配给哪一个过程的记忆,如果一个过程终止,则会收回所有这些记忆。

因此,在实践中,答案是,只要这一过程存在,记忆才会泄露。 之后,该顾问办就座,准备在其他地方重新使用。

当然,这是视窗、赖恩和OSX等共同的主流办案。 一个足够原始的非洲顾问可能无法做到这一点。

这一过程结束后,所有资源都收回。 这包括空间、排位安排等。

All memory claimed by the program is released to the OS when the program terminates, so no, the memory is not lost. When your program finishes, the memory will be available for others.

还有一个问题,即从奇怪的角度来看,它们(分配)使用的记忆是什么?

是的,记忆是RAM。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签