'Visual Studio watch window see object's size/memory footprint
Not sure if it's possible but I'm curious and I haven't had any luck finding this out so far. I'd like to know if anybody knows of a way to determine the size of an object in memory from within the VS watch window. Obviously a profiler could do this, but it would be super convenient just to grab a quick snapshot of this from within VS. Is this possible?
Solution 1:[1]
Not sure if this will help others landing on this question.
In VS2015 you can stop at a break point and use the Diagnostic Tools window.
- Menu
- Debug
- Windows
- Show Diagnostic Tools
- Click
Take Snapshot - Wait for the snapshot to be created.
- Click the blue hyperlinks in the
ObjectsorHeap Sizecolumns - Look at inclusive size for your variable.
HTH.
EDIT: This feature is still present in VS 2022
Solution 2:[2]
- Create a list of your object.
- Add only one object (for string properties add maximum of string length).
- Set a breakpoint before add object.
- Run the project
- Take a "Memory Usage Snapshot" (Tab: Memory Usage under Diagnostic Tools).
- Get another snapshot.
It is not exact, but it is a good guesstimate.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Mehdi |
