0

In a previous thread I posted, it was stated that invoking Array.Empty<int>() would return an object from a memory location which was statically allocated, either at runtime or during the first usage of the static Array class.

However, using Rider's memory feature, I find that even after invoking an unrelated method in the Array class, invoking Array.Empty<int>() makes a new int array with size zero appear on the heap.

Should the object I am seeing appear on the heap already have been there (i.e., in the Before image)? I'm a bit confused.

Before:

enter image description here

After:

enter image description here

  • Does this answer your question? [When do static variables get initialized in C#?](https://stackoverflow.com/questions/3965976/when-do-static-variables-get-initialized-in-c). As the poster for your [prior question](https://stackoverflow.com/questions/72088530/array-emptyint-why-does-rider-show-an-allocation-occurred-but-benchmarkdot) said _"[Array.Empty points to an array that the framework has already **statically allocated**"](https://stackoverflow.com/a/72088610/585968)_ –  May 05 '22 at 05:28
  • @MickyD Thank you. From your second link, I was able to find [this](https://csharpindepth.com/Articles/BeforeFieldInit), which was very useful in answering my question. – user3476332 May 09 '22 at 04:11

0 Answers0