c# - Trying to find object roots using CLR MD -



c# - Trying to find object roots using CLR MD -

here class

namespace mynamespace { public class myclass { private byte[] imagebytes = null; public myclass() { } public void loadimage(string filepath) { image img = image.fromfile(filepath); using (memorystream mstream = new memorystream()) { img.save(mstream, img.rawformat); imagebytes = mstream.toarray(); } } public void removeimage() { imagebytes = null; } } }

and how used

static void main(string[] args) { myclass mc = new myclass(); mc.loadimage(@"c:\images\myimage.jpg"); console.writeline("take process dump now..."); console.read(); mc.removeimage(); }

i run programme , take process snapshot. no surprise, here found references of myclass.

0:000> !dumpheap -type myclass address mt size 0000000002b92e08 000007fe73423a20 24 statistics: mt count totalsize class name 000007fe73423a20 1 24 mynamespace.myclass total 1 objects 0:000> !gcroot 0000000002b92e08 thread 3b3c: 00000000004eef90 000007fe7354011f mytestapp.program.main(system.string[]) [c:\projects\mytestapp\program.cs @ 17] caller.rsp-30: 00000000004eefb0 -> 0000000002b92e08 mynamespace.myclass found 1 unique roots (run '!gcroot -all' see roots).

now see if can same roots myclass instance nowadays in same dump file using clr md . that, using gcroot sample. 1 of inputs application ulong obj. not sure how myclass instance have done within main method of gcroot sample, added followinng code.

foreach (ulong obj2 in heap.enumerateobjects()) { clrtype type2 = heap.getobjecttype(obj2); if (type2.name.startswith("mynamespace.myclass") ) obj = obj2; }

this way see obj getting valid value problem next line of code doesn't find node returns null.

node path = findpathtotarget(heap, root);

as result, not sure how can roots myclass instance dump file. suggestions highly appreciated.

clrmd used create same output !gcroot, gcroot sample not elaborated windbg !gcroot command.

in case, object "myclass" root (local var main thread) , sample returns nothing.

you can check clrroot returned heap.enumerateroots() , find object of type "myclass".

c# .net windbg sos clrmd

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -