I cannot see my lines on the heap during debugging

I am trying to debug a memory issue in a .NET application that works with very large strings. To do this, I would like to set some breakpoints and analyze the bunch at different stages of execution.

The problem is this: when using the diagnostic tools of Visual Studio 2015, it seems that large lines in the heap are displayed only when the application starts without debugging. This is inconvenient because it prevents me from setting breakpoints.

Question : Is this a known bug? Or am I misusing diagnostic tools?


How to play

  • Create a new C # console application (.NET 4.6.1) with the following code:

    using System; using System.Threading; class Program { static void Main(string[] args) { string test1 = new string('a', 100000000); Thread.Sleep(2000); string test2 = new string('a', 100000000); Thread.Sleep(2000); string test3 = new string('a', 100000000); Console.WriteLine("Done"); Console.ReadLine(); } } 
  • Activate the diagnostic tools (Ctrl + Alt + F2) and launch the application using debugging (F5). Pay attention to memory usage and note that each row allocation increases memory usage by 200 MB. After maximum memory usage, take a snapshot of the memory and browse through the heap.

  • Note that the type of object that uses most of the memory on the heap is an icon with 10 KB. Obviously, this is not true.

with debugging

  1. Stop the application. Run it again using the diagnostic tools, but without debugging (Alt + F2). Select "Memory Usage" and run.

  2. Again, pay attention to the increase in memory, take a picture and look at it.

  3. Note that three large lines are shown (as it should be).

enter image description here

+5
source share
1 answer

I found a way to see the lines even when debugging. For some strange reason, the default option β€œJust my code” hides these lines when debugging:

only my code

Deleting a checkmark makes the lines visible.

Apparently this is just a debugging issue. As the second screenshot in the question shows, in the case of "not debugging" the lines are displayed even when "Just my code" is turned on.

+4
source

All Articles