Memory allocation for collections in .NET

前端 未结 2 2082
忘掉有多难
忘掉有多难 2021-01-19 15:33

This might be a dupe. I did not find enough information on this.

I was discussing memory allocation for collections in .Net. Where is the memory for elements alloca

2条回答
  •  没有蜡笔的小新
    2021-01-19 16:02

    The elements will also reside in the heap (in an array, that's how List works internally).

    In principle, only local variables and arguments are be allocated on the stack and everything else goes on the heap (unless you use rare things such as stackalloc, but you don't need to worry about that)

提交回复
热议问题