Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:54:50+00:00 2026-05-17T02:54:50+00:00

I have a small test program. When I look into stack object for main

  • 0

I have a small test program. When I look into stack object for main thread, its showing MyClass twice there. Any ideas why there are two object of MyClass on the stack?

class Program  
{  
    struct MyStruct  
    {  
        int x;  
        int y;  
    }  

    class MyClass 
    {  
        int x;  
        int y;  
    }  


    static void Main(string[] args)  
    {  
        MyStruct s ;  
        MyClass c = new MyClass();  
    }  
}  
0:000> !DumpStackObjects  
OS Thread Id: 0xf74 (0)  
RSP/REG          Object           Name  
000000000023e9e8 00000000028f3c90 ConsoleApplication2.Program+MyClass  
000000000023e9f8 00000000028f3c90 ConsoleApplication2.Program+MyClass  
000000000023ea10 00000000028f3c70 System.Object[]    (System.String[])  
000000000023eb98 00000000028f3c70 System.Object[]    (System.String[])  
000000000023ed80 00000000028f3c70 System.Object[]    (System.String[])  
000000000023eda8 00000000028f3c70 System.Object[]    (System.String[])  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:54:51+00:00Added an answer on May 17, 2026 at 2:54 am

    Actually it shows that the one and only instance is referenced twice. Notice the values in the leftmost column differ. It could be different registers or different parts of the stack frame which point to the same instance.

    In my experience this happens quite often (especially with debug builds). !dso is useful for locating objects and in that case the important column is the Object column, which holds the actual references.

    E.g. if I run your example above from the debugger and place a break point on Main the output from dso looks like this just before the Main method returns.

    0:000> !dso
    OS Thread Id: 0x1944 (0)
    ESP/REG  Object   Name
    eax      0240b2e0 TestApp.Program+MyClass
    ecx      0240b2e0 TestApp.Program+MyClass
    0014F224 0240b2d0 System.Object[]    (System.String[])
    0014F3CC 0240b2d0 System.Object[]    (System.String[])
    0014F400 0240b2d0 System.Object[]    (System.String[])
    

    As you can see both the eax and the ecx registers hold a reference to the instance despite the fact that the C# source only has a single reference.

    If you look at the JIT compiled code for Main it looks like this

    0:000> !u 00200070 
    Normal JIT generated code
    TestApp.Program.Main(System.String[])
    Begin 00200070, size 46
    
    C:\dev2010\TestApp\TestApp\Program.cs @ 33:
    >>> 00200070 55              push    ebp
    00200071 8bec            mov     ebp,esp
    00200073 83ec14          sub     esp,14h
    00200076 33c0            xor     eax,eax
    00200078 8945f4          mov     dword ptr [ebp-0Ch],eax
    0020007b 8945f8          mov     dword ptr [ebp-8],eax
    0020007e 894dfc          mov     dword ptr [ebp-4],ecx
    00200081 833d3c31150000  cmp     dword ptr ds:[15313Ch],0
    00200088 7405            je      0020008f
    0020008a e8c05ac268      call    clr!JIT_DbgIsJustMyCode (68e25b4f)
    0020008f 33d2            xor     edx,edx
    00200091 8955f0          mov     dword ptr [ebp-10h],edx
    00200094 90              nop
    
    C:\dev2010\TestApp\TestApp\Program.cs @ 35:
    00200095 b960391500      mov     ecx,153960h (MT: TestApp.Program+MyClass)
    0020009a e8811ff4ff      call    00142020 (JitHelp: CORINFO_HELP_NEWSFAST)
    0020009f 8945ec          mov     dword ptr [ebp-14h],eax
    002000a2 8b4dec          mov     ecx,dword ptr [ebp-14h]
    002000a5 ff158c391500    call    dword ptr ds:[15398Ch]     (TestApp.Program+MyClass..ctor(), mdToken: 06000003)
    002000ab 8b45ec          mov     eax,dword ptr [ebp-14h]
    002000ae 8945f0          mov     dword ptr [ebp-10h],eax
    
    C:\dev2010\TestApp\TestApp\Program.cs @ 36:
    002000b1 90              nop
    002000b2 8be5            mov     esp,ebp
    002000b4 5d              pop     ebp
    002000b5 c3              ret
    

    Notice the instruction call 00142020. This creates the instance of MyClass and returns the reference in the eax register. Following that the reference is stored at dword ptr [ebp-14h].

    The next instruction reads the value stored at dword ptr [ebp-14h] and stores the value in the ecx register, which is then used as input for the call to the constructor call dword ptr ds:[15398Ch] (TestApp.Program+MyClass..ctor(), mdToken: 06000003).

    This explains why dso lists the reference twice in this case. However, you rarely need to go into the details about this when debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small test program for flipperview. I have 3 views. I call
I have a small program I want to execute to test something #include <map>
I have a small Java test app in Netbeans where the main() class reads
I have written a small test program in which I try to use the
I have a small test program that creates millions of files (for testing purposes)
I have a small program to test passing char* pointers in and out of
I am currently learning to program on iPhone. I currently have a small test
I have an small server/client test program I am running over a radio link
I just written a small program to test something, as below: public class Main
I wrote a small program to test GCC's options. int main() { int a=0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.