One of class has many object present in .NET heap as discovered through following sos command.
!dumpheap -stat -type MyClass
Statistics:
MT Count TotalSize Class Name
00007ff8e6253494 1700 164123 MyNameSpace.MyClass
I need to find the instances of those objects that have ObjSize greater then 5 MB. I know I can list out objsize of all 1700 instances of MyClass using following.
.foreach (res {!DumpHeap -short -MT 00007ff8e6253494 }) {.if ( (!objsize res) > 41943040) {.echo res; !objsize res}}
With the script above, I don't get any results although there are object instances greater than 5MB. I think problem may be that output of objsize is follows
20288 (0x4f40) bytes
Its a string which make it harder to compare against any threshold. How can I get this script to only list objects that has objsize larger then 5MB?
Creating complex scripts in WinDbg is quite error prone. In such situations, I switch to PyKd, which is a WinDbg extension that uses Python.
In the following, I'll only cover the missing piece in your puzzle, which is the parts that does not work:
Here's my starting point:
You can write a script like this (no error handling!)
and use it within your loop:
Note how the size of
!objsizediffers from that of!dumpheap. Just for cross-checking:See also this answer on how to improve the script using
expr()so that you can pass expressions etc. The way I did it now outputs the size in decimal, but that's not explicit. Maybe you want to output a0nprefix to make it clear.