How to get Object Root reference RRS feed

  • Question

  • Hi,

    In my CLR profiler,i am currently getting the Object details (i.e currently in heap) using ProfNativeCallback::ObjectReferences callback method.

    Now, I need the root reference of each object. I am aware that i have to use rootreference2 to get the root reference of each object.From the given example below,

    namespace SampleCsharpappln {  public class C {  public C()        {                    }

    public test(){}    }    public class B : SampleCsharpappln.C    {        public SampleCsharpappln.C k;        public B()        {            k = new SampleCsharpappln.C(); }        public void tigerMethod()        {            k.test(); }    }    public class A : SampleCsharpappln.B    {      public SampleCsharpappln.B t; public A()       {         t = new SampleCsharpappln.B();                   }        public void lionMethod()       {         t.tigerMethod();       } }     in main function,    SampleCsharpappln.A l = new SampleCsharpappln.A();       l.lionMethod();            }

    here, class C which has class B and class A as its root reference. How to obtain this using ObjectReferences and RootReferences2?

    Tuesday, May 30, 2017 7:08 AM

All replies

  • here, class C which has class B and class A as its root reference.

    I'm not sure what you mean, `A` and `B` are classes, not references; also `A.t` and `B.k` are instance fields and so not considered to be root references. Locals and parameters on the other hand, are considered to be root references (so long as the frame is on the stack and the JIT considers the value to be alive). So when execution enters `A.lionMethod()` the `this` reference will be considered a root, but might not be considered a root reference after the call to `tigerMethod()` (if it's jitted as debuggable, then it will be considered a root until the method returns).

    Tuesday, May 30, 2017 9:19 AM
  • sorry brain,

    I think my example not clear, also not in understandable format.
    What i am trying to say is, In my CLR Profiler needs to get complete object reference graph for each object that is present in the heap memory.
    I can get the objects information using ICorProfilerCallback::RootReferences2 callback and ICorProfilerCallback::ObjectReferences callback method.
    I dont know, how to combine the root references information with object references.

    can you help me on this?

    Tuesday, May 30, 2017 12:40 PM
  • I'm not sure I see the problem. To create an object graph, consider all the ObjectId's in the two methods to represent nodes in the graph and the object pairs reported by ObjectReferences to be the edges. If you are not collecting Gen2, then this graph will likely be incomplete, but I don't think there is anything you can do about that.
    Tuesday, May 30, 2017 11:26 PM