在.NET框架中谁将内存分配给托管堆中的对象? [英] In .NET framework who allocates memory to object in managed heap?

查看:91
本文介绍了在.NET框架中谁将内存分配给托管堆中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我做任何对象例如:

If I make any object for example :

Emp obj= new Emp();



那么谁clr,系统(OS)或垃圾收集器会将内存分配给堆中的 obj 对象吗?



1.提取1:垃圾收集器结束负责。

来自micorsoft

链接 - < a href =https://msdn.microsoft.com/en-us/library/f144e03t(v=vs .110).aspx>

< / a>

提取:当应用程序创建下一个对象时,垃圾收集器在地址空间中为它分配内存紧接着第一个对象。只要地址空间可用,垃圾收集器就会继续以这种方式为新对象分配空间。



2.Extract 2:clr将负责哪些结论如果堆已满,则只会调用内存分配和gc。



link -

[ ^ ]



任何人都可以告诉我gc是否真的负责为对象分配内存。



我尝试了什么:



1.摘录1:垃圾收集器的结论是负责。

来自micorsoft

链接 - < a href =https://msdn.microsoft.com/en-us/library/f144e03t(v=vs。 110).aspx>

< / a>

提取:当应用程序创建下一个对象时,垃圾收集器分配m紧跟在第一个对象之后的地址空间中的emory。只要地址空间可用,垃圾收集器就会继续以这种方式为新对象分配空间。



2.Extract 2:clr将负责哪些结论如果堆已满,则只会调用内存分配和gc。



link -

[ ^ ]


So who clr , system(OS) or garbage collector will allocate memory to obj object in heap ?

1. Extract 1 :Which concludes garbage collector is responsible.
From micorsoft
link -<a href="https://msdn.microsoft.com/en-us/library/f144e03t(v=vs.110).aspx">
</a>
Extract :When the application creates the next object, the garbage collector allocates memory for it in the address space immediately following the first object. As long as address space is available, the garbage collector continues to allocate space for new objects in this manner.

2.Extract 2: Which concludes clr will be responsible for memory allocation and gc will only be called if heap is full.

link -
[^]

Can anybody really tell me if gc is really responsible for allocating memory to an object.

What I have tried:

1. Extract 1 :Which concludes garbage collector is responsible.
From micorsoft
link -<a href="https://msdn.microsoft.com/en-us/library/f144e03t(v=vs.110).aspx">
</a>
Extract :When the application creates the next object, the garbage collector allocates memory for it in the address space immediately following the first object. As long as address space is available, the garbage collector continues to allocate space for new objects in this manner.

2.Extract 2: Which concludes clr will be responsible for memory allocation and gc will only be called if heap is full.

link -
[^]

推荐答案

两者:垃圾收集器是CLR的一部分,用于清理并释放内存。它控制着Heap和它的空闲内存列表,因此它也可以分配内存:自动内存管理 [ ^ ]

系统分配内存以便在应用程序启动时启动(对于每个启动的线程,因为它们都具有不受控制的独立堆栈然后由GC负责。

听听MSDN的说法,而不是像Telerik这样的第三方 - 如果你真的需要知道细节,我肯定GC深埋在参考源 [ ^ ]
Both: the Garbage Collector is part of the CLR and works to clean up after you and free memory. It is in control of the Heap and it's free memory lists, so it also does the allocation of memory: Automatic Memory Management[^]
The system allocates the memory to start with when your app starts (and for each thread you start as they all have independent stacks which are not controlled by the GC), and the GC is responsible for it after that.
Listen to what MSDN says, not a third party like Telerik - and if you really need to know the details, I'm sure the GC is buried somewhere deep in the Reference Source[^]


这篇关于在.NET框架中谁将内存分配给托管堆中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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