How does the C# garbage collector find objects whose only reference is an interior pointer?

前端 未结 3 1607
感动是毒
感动是毒 2020-12-14 03:09

In C#, ref and out params are, as far as I know, passed by passing only the raw address of the relevant value. That address may be an interior poin

3条回答
  •  佛祖请我去吃肉
    2020-12-14 03:42

    Your code compiles to

        IL_0001: newobj instance void Foo::.ctor()
        IL_0006: ldflda int32 Foo::'field'
        IL_000b: call void Foo::Increment(int32&)
    

    AFAIK, the ldflda instruction creates a reference to the object containing the field, for as long as the address is on the stack (until the call completes).

提交回复
热议问题