Question

I am using Scitech's .Net Memory Profiler to check some stuff in my app (running on WinXP 64). I am seeing a lot cases where there is a single live instance of a list my app uses which is always 32 bytes and shows up as an array (for example Products[]).

When I take a closer look at the instance it doesn't look like it is referenced by anything. If I leave the "Only show instances included in root paths" checkbox checked, the referenced by list is empty. If I uncheck that checkbox, I only see:

Object[]    #307[9126]
    <GCHandle>  #306 {Pinned}

The allocation call stack looks like:

mscorlib!System.Collections.Generic.List<T>..cctor()
[Skipped frame(s)]
mscorlib!System.Collections.ObjectModel.Collection<T>..ctor()
MyApp.ProductsAdmin!MyApp.ProductsAdmin.ViewModels.ProductsAdminViewModel..ctor() ProductsAdminViewModel.cs

It looks like its just ending on the construction of an empty list. What does it mean when there are no instances included in root paths and all I see is Pinned?

Was it helpful?

Solution

The reason is that List static constructor allocate an empty array of T. Take a look on its code using Reflector:

static List()
{
    List<T>._emptyArray = new T[0];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top