You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
byte*ptr=Marshal.AllocHGlobal(...);refbyteb=refUnsafe.AsRef<byte>(ptr);Use(refb);Marshal.FreeHGlobal(ptr);// `b` never used again in the code. Let's assume JIT decided to extend the `b` variable lifetime till end of the method.objecto=newobject();// Let's assume that the GC run out of space, allocated a new memory block using virtual alloc, and the OS memory manager decides to give it the memory block that was just freed by `Marshal.FreeHGlobal`.GC.Collect();// The GC may assert or crash because of it will see `byref b` pointing into middle of the segment where no valid byrefs are supposed to point to