Replies: 1 comment
-
Pointers are unknown to GC and can be leaked into unmanaged code. Thus obtaining a pointer requires pinning.
Neither. It doesn't require pinning, like normal object reference. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
C# has some pointer-like type such as pointers, refs, and Span. But how these types avoid pointers getting invalidated due to memory relocation by GC. I think it is common to use the fixed statement for pinning to acquire array references. However, ref, Span, Unsafe.AsPointer(), etc. do not perform pinning. Is the pinning actually done, or does the relocation sometimes cause an error?
I found an answer that seems relevant, but even if that is the case I don't know when or how it is performed.
https://stackoverflow.com/questions/47419240/how-does-the-c-sharp-garbage-collector-find-objects-whose-only-reference-is-an-i
Beta Was this translation helpful? Give feedback.
All reactions