Kiran
Kiran

Reputation: 57949

Unable to find expected objects in VS 2015 memory usage profiler

I have the following simple program which I am trying to use with VS 2015's Diagnostic Tools related to Memory Usage.

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Begin");
        Console.ReadLine();
        Goo();
        Console.WriteLine("End");
        Console.ReadLine();
    }

    private static void Goo()
    {
        var list = new List<string>();
        for (var i = 0; i < 1000; i++)
        {
            Foo(list);
        }
    }

    private static void Foo(IEnumerable<string> strings)
    {
        foreach (var str in strings)
        {

        }
    }
}

While profiling this application's project, I took couple of snapshots and was expecting to see 1000 boxed List<string>+Enumerator objects. For example, I get this kind of information in JetBrains's dotMemory product. But for some reason, I am unable to see this information in VS's tool...I am obviously missing something...can anyone point me in the right direction?

enter image description here

As you can see in the above snapshot, I get information about the mscorlib module only where as I do not see any information about my executing program. What am I missing?...some more info below:

Updated(responding to user answer): I am using dotMemory version 4.4. Following is a snapshot of the data I get from it. NOTE: make sure to click the button Collect Allocations before you hit any key after seeing the Begin message

enter image description here

Upvotes: 3

Views: 600

Answers (2)

Patrick Nelson - MSFT
Patrick Nelson - MSFT

Reputation: 3170

The memory analysis tool works by iterating all of the GC roots and traversing the object graphs from there - similar to what the GC does. Once the method is out of scope, the local variable containing the enumerator is no longer a GC root. Any heap objects whose reference is stored in a local and is not referenced through another GC root are unreachable and essentially gone at that point.

Upvotes: 2

Ed Pavlov
Ed Pavlov

Reputation: 2508

All objects created in Goo and Foo already collected when you get snapshot at "End" point. I profiled this code with dotMemory 10.0.1 and also do not see any objects created in Goo and Foo methods.

UPDATE: In dotMemory you are looking at "Memory Traffic" view. Memory traffic - are objects created and possible already collected to the point of time. dotMemory shows you a warning that it is not able to display collected objects. If you check "Start collecting allocation data immediatelly" checkbox in the profiling setup dialog, dotMemory will show you that these 1000 objects were allocated and already collected. In VS Diagnostic Tools you are looking at live objects graph. I'm not very familliar with this tool, but it seems that there is no information about memory traffic.

If you look at live objects graph in dotMemory ("All objects" view), you won't find these objects too.

Upvotes: 2

Related Questions