using System.Runtime.CompilerServices; ... LargeObject obj = new LargeObject(); GCHandledObjects.Add(obj); // "Pins" the object in memory
using System.Runtime.CompilerServices; ... LargeObject obj = new LargeObject(); WeakReference reference = GCHandle.Alloc(obj, GCHandleType.Weak);In these examples, the GCHandledObjects class and GCHandle class are part of the System.Runtime.CompilerServices namespace in the .NET framework.