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.

Stop the application. Run it again using the diagnostic tools, but without debugging (Alt + F2). Select "Memory Usage" and run.
Again, pay attention to the increase in memory, take a picture and look at it.
Note that three large lines are shown (as it should be).

source share