According to the C# reference for fixed
statement:
The fixed statement prevents the garbage collector from relocating a movable variable. ... After the code in the statement is executed, any pinned variables are unpinned and subject to garbage collection. Therefore, do not point to those variables outside the fixed statement.
What I haven't found on this page: What will it be if we have nested the fixed
statement for the same variable?
var data = new byte[100];
unsafe
{
fixed(byte* pData = data)
{
//pData points to the "pinned" variable
fixed(byte* pData2 = data)
{
//pData points to the "pinned" variable
//pData2 points to the "pinned" variable
}
//Does pData still point to the "pinned" variable?
}
}
The code above is thought of course only for illustration. The practical use could be recursive functions.