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?
I think this is not possible. See Size of a managed object (rather old but seems still valid).
You can have an object size in the Immediate window. See my answer in Find out the size of a .net object.
You can write a function in your code (adapted from above meant thread) and reference it from watch.
Public Function GetSerializedSize(myObject As Object) As Long
Using ms As New IO.MemoryStream
Dim bf As New Runtime.Serialization.Formatters.Binary.BinaryFormatter()
bf.Serialize(ms, myObject)
GetSerializedSize = ms.Position
End Using
End Function
However, this is neither precise (I am getting 2 times smaller value for DatataTable) nor convenient (the value has to be manually refreshed), but it gives you some clue.
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.
Take Snapshot
Objects
or Heap Size
columnsHTH.
EDIT: This feature is still present in VS 2022
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With