8 instantiations of GCHandle
PresentationCore (1)
src\wpf\src\Microsoft.DotNet.Wpf\src\Shared\MS\Internal\CharacterBuffer.cs (1)
428gcHandle = new GCHandle();
System.Private.CoreLib (3)
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\GCHandle.cs (3)
65public static GCHandle Alloc(object? value) => new GCHandle(value, GCHandleType.Normal); 72public static GCHandle Alloc(object? value, GCHandleType type) => new GCHandle(value, type); 161return new GCHandle(value);
System.Speech (4)
Internal\Synthesis\ConvertTextFrag.cs (2)
31sapiFrag.gcNext = fFirst ? new GCHandle() : sapiFragLast; 75sapiFrag.gcPhoneme = new GCHandle();
Internal\Synthesis\TTSEngineProxy.cs (1)
152GCHandle spvTextFragment = new();
Internal\Synthesis\TTSVoice.cs (1)
94GCHandle targetFormat = new();
568 references to GCHandle
aspire (2)
Processes\DetachedProcessLauncher.Windows.cs (2)
61var pinnedHandles = GCHandle.Alloc(handles, GCHandleType.Pinned);
ILCompiler.ReadyToRun (5)
src\runtime\src\coreclr\tools\Common\JitInterface\CorInfoImpl.cs (4)
642private Dictionary<object, GCHandle> _pins = new Dictionary<object, GCHandle>(); 646GCHandle handle; 649handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
TypeSystem\Mutable\MutableModule.cs (1)
215System.Runtime.InteropServices.GCHandle.Alloc(metadataArray, System.Runtime.InteropServices.GCHandleType.Pinned);
ILCompiler.RyuJit (4)
src\runtime\src\coreclr\tools\Common\JitInterface\CorInfoImpl.cs (4)
642private Dictionary<object, GCHandle> _pins = new Dictionary<object, GCHandle>(); 646GCHandle handle; 649handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
libmscordaccore_universal (7)
Entrypoints.cs (7)
84GCHandle gcHandle = GCHandle.Alloc(target); 85*handle = GCHandle.ToIntPtr(gcHandle); 100GCHandle h = GCHandle.FromIntPtr(handle); 127Target? target = GCHandle.FromIntPtr(handle).Target as Target; 167Target? target = GCHandle.FromIntPtr(handle).Target as Target;
Microsoft.CSharp (5)
Microsoft\CSharp\RuntimeBinder\ComInterop\ComInvokeBinder.cs (3)
107get { return EnsureVariable(ref _dispIdsOfKeywordArgsPinned, typeof(GCHandle), "dispIdsOfKeywordArgsPinned"); } 377typeof(GCHandle).GetMethod(nameof(GCHandle.Free))
Microsoft\CSharp\RuntimeBinder\ComInterop\ComRuntimeHelpers.cs (2)
325public static IntPtr GetIdsOfNamedParameters(IDispatch dispatch, string[] names, int methodDispId, out GCHandle pinningHandle) 327pinningHandle = GCHandle.Alloc(null, GCHandleType.Pinned);
Microsoft.Diagnostics.DataContractReader.Legacy (58)
ClrDataMethodDefinition.cs (4)
170GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)(*handle)); 232GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)handle);
ClrDataModule.cs (4)
329GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)(*handle)); 384GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)handle);
Dbi\DacDbiImpl.cs (22)
529GCHandle dacHandle = GCHandle.Alloc(dacAssemblies); 532int hrLocal = _legacy.EnumerateAssembliesInAppDomain(vmAppDomain, &CollectEnumerationCallback, GCHandle.ToIntPtr(dacHandle)); 694GCHandle dacHandle = GCHandle.Alloc(dacThreads); 695int hrLocal = _legacy.EnumerateThreads(&CollectEnumerationCallback, GCHandle.ToIntPtr(dacHandle)); 713GCHandle handle = GCHandle.FromIntPtr(pUserData); 1393GCHandle dacHandle = GCHandle.Alloc(dacFrames); 1394int hrLocal = _legacy.EnumerateInternalFrames(vmThread, (delegate* unmanaged<Debugger_STRData*, void*, void>)&CollectStubFrameCallback, GCHandle.ToIntPtr(dacHandle)); 1423GCHandle handle = GCHandle.FromIntPtr((nint)pUserData); 2100GCHandle handle = GCHandle.FromIntPtr((nint)pUserData); 2109GCHandle dacHandle = GCHandle.Alloc(dacFields); 2111int hrLocal = legacyEnumerate(&dacObjectSize, GCHandle.ToIntPtr(dacHandle)); 3260GCHandle gcHandle = GCHandle.FromIntPtr((nint)handle); 3295GCHandle gcHandle = GCHandle.FromIntPtr((nint)handle);
IEnum.cs (3)
14GCHandle gcHandle = GCHandle.Alloc(this); 15return GCHandle.ToIntPtr(gcHandle).ToInt64();
MetaDataImportImpl.cs (7)
71GCHandle handle = GCHandle.Alloc(e); 72nint ptr = GCHandle.ToIntPtr(handle); 81GCHandle handle = GCHandle.FromIntPtr(hEnum); 116GCHandle handle = GCHandle.FromIntPtr(hEnum);
NativeStringHolder.cs (2)
22private readonly GCHandle _delegateHandle; 35_delegateHandle = GCHandle.Alloc(assignCopy);
SOSDacImpl.cs (12)
4601var expected = (TraverseEhInfoExpected)GCHandle.FromIntPtr((nint)expectedEhInfo).Target!; 4700GCHandle expectedHandle = GCHandle.Alloc(expected); 4703void* tokenDebug = GCHandle.ToIntPtr(expectedHandle).ToPointer(); 4809var expectedElementsDict = (Dictionary<ulong, uint>)GCHandle.FromIntPtr((nint)expectedElements).Target!; 4859void* tokenDebug = GCHandle.ToIntPtr(GCHandle.Alloc(expectedElements)).ToPointer(); 4865GCHandle.FromIntPtr((nint)tokenDebug).Free(); 4874var expectedElementsDict = (Dictionary<ulong, ulong>)GCHandle.FromIntPtr((nint)expectedElements).Target!; 4918GCHandle expectedElementsHandle = GCHandle.Alloc(expectedElements); 4919void* tokenDebug = GCHandle.ToIntPtr(expectedElementsHandle).ToPointer();
SOSDacImpl.IXCLRDataProcess.cs (4)
513GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)(*handle)); 581GCHandle gcHandle = GCHandle.FromIntPtr((IntPtr)handle);
Microsoft.ML.LightGbm (6)
WrappedLightGbmDataset.cs (6)
52GCHandle[] gcValues = new GCHandle[numCol]; 53GCHandle[] gcIndices = new GCHandle[numCol]; 60gcValues[i] = GCHandle.Alloc(sampleValuePerColumn[i], GCHandleType.Pinned); 62gcIndices[i] = GCHandle.Alloc(sampleIndicesPerColumn[i], GCHandleType.Pinned);
Microsoft.ML.Mkl.Components (12)
SymSgdClassificationTrainer.cs (12)
341public GCHandle GcHandle; 346GcHandle = GCHandle.Alloc(Buffer, GCHandleType.Pinned); 487public void GiveArrayOfSize(int size, out GCHandle? outGcHandle, out int outArrayStartIndex) 663public bool GiveNextInstance(out InstanceProperties? prop, out GCHandle? indicesGcHandle, out int indicesStartIndex, 664out GCHandle? valuesGcHandle, out int valuesStartIndex) 736GCHandle stateGCHandle = default; 739stateGCHandle = GCHandle.Alloc(state, GCHandleType.Pinned); 863int numThreads, bool tuneNumLocIter, ref int numLocIter, float tolerance, bool needShuffle, bool shouldInitialize, GCHandle stateGCHandle, ChannelCallBack info) 878while (inputDataManager.GiveNextInstance(out InstanceProperties? prop, out GCHandle? indicesGcHandle, out int indicesStartIndex, out GCHandle? valuesGcHandle, out int valuesStartIndex)) 917public static void MapBackWeightVector(Span<float> weightVector, GCHandle stateGCHandle) 926public static void DeallocateSequentially(GCHandle stateGCHandle)
Microsoft.ML.Vision (4)
ImageClassificationTrainer.cs (4)
975var featureBufferHandle = GCHandle.Alloc(featuresBuffer, GCHandleType.Pinned); 977var labelBufferHandle = GCHandle.Alloc(labelBuffer, GCHandleType.Pinned);
Microsoft.NET.StringTools (2)
WeakStringCache.cs (2)
36private GCHandle weakHandle; 80weakHandle = GCHandle.Alloc(str, GCHandleType.Weak);
Microsoft.Private.Windows.Core (17)
Windows\Win32\PInvokeCore.EnumChildWindows.cs (3)
23GCHandle gcHandle = GCHandle.Alloc(callback); 44return ((EnumChildWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\PInvokeCore.EnumDisplayMonitors.cs (3)
19GCHandle gcHandle = GCHandle.Alloc(callBack); 39return ((EnumDisplayMonitorsCallback)((GCHandle)(nint)lParam).Target!)(monitor, hdc);
Windows\Win32\PInvokeCore.EnumThreadWindows.cs (3)
25GCHandle gcHandle = GCHandle.Alloc(callback); 48return ((EnumThreadWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\PInvokeCore.EnumWindows.cs (3)
22GCHandle gcHandle = GCHandle.Alloc(callback); 42return ((EnumWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\System\Com\Lifetime.cs (5)
31GCHandle.FromIntPtr((nint)lifetime->_handle).Free(); 44/// This creates a <see cref="GCHandle"/> to root the <paramref name="object"/> until ref 58wrapper->_handle = (void*)GCHandle.ToIntPtr(GCHandle.Alloc(@object)); 75return (TObject?)GCHandle.FromIntPtr((IntPtr)lifetime->_handle).Target;
Mono.Cecil.Pdb (2)
Mono.Cecil.Pdb\SymWriter.cs (2)
153 var handle = GCHandle.Alloc (metadata, GCHandleType.Pinned);
mscorlib (1)
src\runtime\src\libraries\shims\mscorlib\ref\mscorlib.cs (1)
691[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.GCHandle))]
netstandard (1)
netstandard.cs (1)
1696[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.GCHandle))]
PresentationCore (23)
MS\Internal\FontCache\FontSource.cs (2)
397_memoryHandle = GCHandle.Alloc(bits, GCHandleType.Pinned); 423private GCHandle _memoryHandle;
MS\Internal\Shaping\TypefaceMap.cs (1)
91GCHandle gcHandle;
src\wpf\src\Microsoft.DotNet.Wpf\src\Shared\MS\Internal\CharacterBuffer.cs (10)
39public abstract IntPtr PinAndGetCharacterPointer(int offset, out GCHandle gcHandle); 44public abstract void UnpinCharacterPointer(GCHandle gcHandle); 218public override unsafe IntPtr PinAndGetCharacterPointer(int offset, out GCHandle gcHandle) 220gcHandle = GCHandle.Alloc(_characterArray, GCHandleType.Pinned); 227public override void UnpinCharacterPointer(GCHandle gcHandle) 317public override unsafe IntPtr PinAndGetCharacterPointer(int offset, out GCHandle gcHandle) 319gcHandle = GCHandle.Alloc(_string, GCHandleType.Pinned); 326public override void UnpinCharacterPointer(GCHandle gcHandle) 426public override IntPtr PinAndGetCharacterPointer(int offset, out GCHandle gcHandle) 435public override void UnpinCharacterPointer(GCHandle gcHandle)
System\Windows\Media\EventProxy.cs (5)
31((System.Runtime.InteropServices.GCHandle)(pEPD.m_handle)).Free(); 34internal System.Runtime.InteropServices.GCHandle m_handle; 105System.Runtime.InteropServices.GCHandle handle = (System.Runtime.InteropServices.GCHandle)(epd.m_handle); 138m_handle = System.Runtime.InteropServices.GCHandle.Alloc(epw, System.Runtime.InteropServices.GCHandleType.Normal)
System\Windows\Media\StreamAsIStream.cs (5)
55((System.Runtime.InteropServices.GCHandle)(pSD.m_handle)).Free(); 58internal System.Runtime.InteropServices.GCHandle m_handle; 510System.Runtime.InteropServices.GCHandle handle = (System.Runtime.InteropServices.GCHandle)(sd.m_handle); 657sd.m_handle = System.Runtime.InteropServices.GCHandle.Alloc(sais, System.Runtime.InteropServices.GCHandleType.Normal);
PresentationFramework (12)
MS\Internal\WindowsRuntime\Generated\WinRT\Marshalers.cs (5)
16public static void Dispose(this GCHandle handle) 35public GCHandle _gchandle; 51m._gchandle = GCHandle.Alloc(value, GCHandleType.Pinned); 276public MarshalerArray(Array array) => _gchandle = GCHandle.Alloc(array, GCHandleType.Pinned); 279public GCHandle _gchandle;
System\Windows\Documents\WinEventHandler.cs (2)
33_gchThis = GCHandle.Alloc(_winEventProc); 162private GCHandle _gchThis;
System\Windows\Standard\MessageWindow.cs (5)
56GCHandle gcHandle = default(GCHandle); 59gcHandle = GCHandle.Alloc(this); 149GCHandle gcHandle = GCHandle.FromIntPtr(createStruct.lpCreateParams);
System.Data.OleDb (4)
ColumnBinding.cs (4)
46private GCHandle _pinnedBuffer; 700_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned); 747_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned); 766_pinnedBuffer = GCHandle.Alloc(value, GCHandleType.Pinned);
System.Diagnostics.EventLog (10)
System\Diagnostics\EventLog.cs (5)
889GCHandle[] handles = new GCHandle[insertionStrings.Length]; 890GCHandle stringsRoot = GCHandle.Alloc(addresses, GCHandleType.Pinned); 901handles[i] = GCHandle.Alloc(insertionStrings[i], GCHandleType.Pinned);
System\Diagnostics\EventLogInternal.cs (5)
1380GCHandle[] stringHandles = new GCHandle[strings.Length]; 1381GCHandle stringsRootHandle = GCHandle.Alloc(stringRoots, GCHandleType.Pinned); 1386stringHandles[strIndex] = GCHandle.Alloc(strings[strIndex], GCHandleType.Pinned);
System.DirectoryServices (3)
Interop\AdsValueHelper2.cs (3)
44private GCHandle _pinnedHandle; 265_pinnedHandle = GCHandle.Alloc(managedValue, GCHandleType.Pinned); 274_pinnedHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
System.Drawing.Common (2)
System\Drawing\Font.cs (2)
293GCHandle handle = GCHandle.Alloc(logFont, GCHandleType.Pinned);
System.Net.Http.WinHttpHandler (14)
System\Net\Http\WinHttpHandler.cs (2)
1310GCHandle pinnedHandle = GCHandle.Alloc(proxyInfo, GCHandleType.Pinned);
System\Net\Http\WinHttpRequestState.cs (12)
31private GCHandle _operationHandle; 49_operationHandle = GCHandle.Alloc(this); 55GCHandle stateHandle = GCHandle.FromIntPtr(gcHandle); 61return GCHandle.ToIntPtr(_operationHandle); 159private GCHandle _cachedReceivePinnedBuffer; 160private GCHandle _cachedSendPinnedBuffer; 171_cachedReceivePinnedBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned); 184_cachedSendPinnedBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned); 212_cachedReceivePinnedBuffer = default(GCHandle); 218_cachedSendPinnedBuffer = default(GCHandle); 224_operationHandle = default(GCHandle);
System.Net.Quic (34)
System\Net\Quic\Internal\MsQuicSafeHandle.cs (2)
91private GCHandle _context; 112public unsafe MsQuicContextSafeHandle(QUIC_HANDLE* handle, GCHandle context, SafeHandleType safeHandleType, MsQuicSafeHandle? parent = null)
System\Net\Quic\Internal\ResettableValueTaskSource.cs (5)
34private GCHandle _keepAlive; 102_keepAlive = GCHandle.Alloc(keepAlive); 324GCHandle handle = GCHandle.Alloc(keepAlive); 327((GCHandle)state!).Free();
System\Net\Quic\Internal\ValueTaskSource.cs (2)
28private GCHandle _keepAlive; 85_keepAlive = GCHandle.Alloc(keepAlive);
System\Net\Quic\QuicConnection.cs (10)
319GCHandle context = GCHandle.Alloc(this, GCHandleType.Weak); 326(void*)GCHandle.ToIntPtr(context), 353GCHandle context = GCHandle.Alloc(this, GCHandleType.Weak); 361(void*)GCHandle.ToIntPtr(context)); 572GCHandle keepObject = GCHandle.Alloc(this); 784GCHandle stateHandle = GCHandle.FromIntPtr((IntPtr)context);
System\Net\Quic\QuicListener.cs (7)
123GCHandle context = GCHandle.Alloc(this, GCHandleType.Weak); 130(void*)GCHandle.ToIntPtr(context), 182GCHandle keepObject = GCHandle.Alloc(this); 373GCHandle stateHandle = GCHandle.FromIntPtr((IntPtr)context);
System\Net\Quic\QuicStream.cs (8)
198GCHandle context = GCHandle.Alloc(this, GCHandleType.Weak); 206(void*)GCHandle.ToIntPtr(context), 240GCHandle context = GCHandle.Alloc(this, GCHandleType.Weak); 251(void*)GCHandle.ToIntPtr(context)); 715GCHandle stateHandle = GCHandle.FromIntPtr((IntPtr)context);
System.Net.Requests (2)
System\Net\TimerThread.cs (2)
207_thisHandle = (IntPtr)GCHandle.Alloc(this); 247((GCHandle)_thisHandle).Free();
System.Net.Security (6)
src\runtime\src\libraries\Common\src\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSsl.cs (4)
1230GCHandle gch = GCHandle.FromIntPtr(ptr); 1262GCHandle gch = GCHandle.FromIntPtr(ptr);
src\runtime\src\libraries\Common\src\Interop\Unix\System.Security.Cryptography.Native\Interop.SslCtx.cs (2)
84private GCHandle _gch; 172_gch = GCHandle.Alloc(this);
System.Net.Sockets (12)
System\Net\Sockets\SocketPal.Unix.cs (12)
299Span<GCHandle> handles = allocOnStack ? stackalloc GCHandle[IovStackThreshold] : new GCHandle[maxBuffers]; 311handles[i] = GCHandle.Alloc(buffer.Array, GCHandleType.Pinned); 411Span<GCHandle> handles = allocOnStack ? stackalloc GCHandle[IovStackThreshold] : new GCHandle[maxBuffers]; 425handles[i] = GCHandle.Alloc(buffer.Array, GCHandleType.Pinned); 553Span<GCHandle> handles = allocOnStack ? stackalloc GCHandle[IovStackThreshold] : new GCHandle[buffersCount]; 564handles[i] = GCHandle.Alloc(buffer.Array, GCHandleType.Pinned);
System.Numerics.Tensors (2)
System\Numerics\Tensors\netcore\Tensor_1.cs (2)
210GCHandle handle = GCHandle.Alloc(_values, GCHandleType.Pinned);
System.Private.CoreLib (145)
Internal\Runtime\CompilerServices\OpenMethodResolver.cs (4)
31private readonly GCHandle _readerGCHandle; 37public OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, int slot, GCHandle readerGCHandle, int handle) 47public OpenMethodResolver(RuntimeTypeHandle declaringTypeOfSlot, RuntimeMethodHandle gvmSlot, GCHandle readerGCHandle, int handle) 60public OpenMethodResolver(RuntimeTypeHandle declaringType, IntPtr codePointer, GCHandle readerGCHandle, int handle, short resolveType)
src\runtime\src\libraries\System.Private.CoreLib\src\System\Buffers\MemoryHandle.cs (2)
14private GCHandle _handle; 24public MemoryHandle(void* pointer, GCHandle handle = default, IPinnable? pinnable = default)
src\runtime\src\libraries\System.Private.CoreLib\src\System\ComAwareWeakReference.cs (11)
86GCHandle.InternalFree(_weakHandle); 98GCHandle.InternalSet(_weakHandle, target); 103internal object? Target => GCHandle.InternalGet(_weakHandle); 115target = Unsafe.As<T>(GCHandle.InternalGet(_weakHandle)); 122GCHandle.InternalSet(_weakHandle, target); 136nint newHandle = GCHandle.InternalAlloc(newRef, GCHandleType.Normal); 145GCHandle.InternalFree(newHandle); 149return Unsafe.As<ComAwareWeakReference>(GCHandle.InternalGet(taggedHandle & ~HandleTagBits)!); 156return Unsafe.As<ComAwareWeakReference>(GCHandle.InternalGet(taggedHandle & ~HandleTagBits)!); 164Unsafe.As<ComAwareWeakReference>(GCHandle.InternalGet(taggedHandle & ~HandleTagBits)!); 174nint newHandle = GCHandle.InternalAlloc(comAwareRef, GCHandleType.Normal);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\EventProvider.cs (3)
617GCHandle[] rgGCHandle = new GCHandle[refObjIndex]; 622rgGCHandle[i] = GCHandle.Alloc(dataRefObj[i], GCHandleType.Pinned);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\DataCollector.cs (5)
27private GCHandle* pinsEnd; 31private GCHandle* pins; 42GCHandle* pins, 312GCHandle* pinsTemp = this.pins; 327*pinsTemp = GCHandle.Alloc(value, GCHandleType.Pinned);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Diagnostics\Tracing\TraceLogging\TraceLoggingEventSource.cs (5)
431GCHandle* pins = stackalloc GCHandle[pinCount]; 609GCHandle* pins = stackalloc GCHandle[pinCount]; 720private static unsafe void WriteCleanup(GCHandle* pPins, int cPins)
src\runtime\src\libraries\System.Private.CoreLib\src\System\IO\PinnedBufferMemoryStream.cs (2)
15private GCHandle _pinningHandle; 22_pinningHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Memory.cs (4)
401GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned); 420GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
src\runtime\src\libraries\System.Private.CoreLib\src\System\ReadOnlyMemory.cs (4)
316GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned); 335GCHandle handle = GCHandle.Alloc(tmpObject, GCHandleType.Pinned);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\ComWrappers.cs (26)
229return Unsafe.As<ManagedObjectWrapperHolder>(GCHandle.FromIntPtr(handle).Target); 380GCHandle.InternalFree(handle); 520if (refCountedHandle != IntPtr.Zero && GCHandle.InternalGet(refCountedHandle) != null) 550private GCHandle _proxyHandle; 551private GCHandle _proxyHandleTrackingResurrection; 596_proxyHandle = GCHandle.Alloc(comProxy, GCHandleType.Weak); 603_proxyHandleTrackingResurrection = GCHandle.Alloc(comProxy, GCHandleType.WeakTrackResurrection); 619internal GCHandle ProxyHandle => _proxyHandle; 672internal readonly GCHandle _nativeObjectWrapperWeakHandle; 704_nativeObjectWrapperWeakHandle = GCHandle.Alloc(this, GCHandleType.Weak); 1302private readonly Dictionary<IntPtr, GCHandle> _cache = []; 1317ref GCHandle rcwEntry = ref CollectionsMarshal.GetValueRefOrAddDefault(_cache, comPointer, out bool exists); 1322rcwEntry = GCHandle.Alloc(wrapper, GCHandleType.Weak); 1360if (!_cache.TryGetValue(comPointer, out GCHandle existingHandle)) 1385if (_cache.TryGetValue(comPointer, out GCHandle existingHandle) 1440if (_cache.TryGetValue(comPointer, out GCHandle cachedRef) 1679internal sealed class GCHandleSet : IEnumerable<GCHandle> 1689public void Add(GCHandle handle) 1763public void Remove(GCHandle handle) 1792private static int GetBucket(GCHandle handle, int numBuckets) 1800IEnumerator<GCHandle> IEnumerable<GCHandle>.GetEnumerator() => GetEnumerator(); 1802IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<GCHandle>)this).GetEnumerator(); 1807public GCHandle _value; 1810public struct Enumerator : IEnumerator<GCHandle> 1825public GCHandle Current
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\GCHandle.cs (13)
28public partial struct GCHandle : IEquatable<GCHandle> 65public static GCHandle Alloc(object? value) => new GCHandle(value, GCHandleType.Normal); 72public static GCHandle Alloc(object? value, GCHandleType type) => new GCHandle(value, type); 156public static explicit operator GCHandle(IntPtr value) => FromIntPtr(value); 158public static GCHandle FromIntPtr(IntPtr value) 165public static explicit operator IntPtr(GCHandle value) => ToIntPtr(value); 167public static IntPtr ToIntPtr(GCHandle value) => value._handle; 171public override readonly bool Equals([NotNullWhen(true)] object? o) => o is GCHandle other && Equals(other); 176public readonly bool Equals(GCHandle other) => _handle == other._handle; 178public static bool operator ==(GCHandle a, GCHandle b) => a._handle == b._handle; 180public static bool operator !=(GCHandle a, GCHandle b) => a._handle != b._handle;
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\GCHandle.T.cs (9)
21/// <seealso cref="GCHandle" /> 35_handle = GCHandle.InternalAlloc(target, GCHandleType.Normal); 50GCHandle.CheckUninitialized(handle); 52return Unsafe.As<T>(GCHandle.InternalGet(handle)!); 57GCHandle.CheckUninitialized(handle); 58GCHandle.InternalSet(handle, value); 71/// interchangable with <see cref="GCHandle"/>. 83/// interchangable with <see cref="GCHandle"/>. 97GCHandle.InternalFree(handle);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\Java\JavaMarshal.Unsupported.cs (7)
54/// with the handle and can be retrieved by the runtime via <see cref="GetContext(GCHandle)"/>. 57/// <returns>A <see cref="GCHandle"/> that represents the allocated reference-tracking handle.</returns> 60public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* context) 69/// <param name="obj">The <see cref="GCHandle"/> whose context should be returned.</param> 77public static unsafe void* GetContext(GCHandle obj) 89/// <param name="unreachableObjectHandles">A span of <see cref="GCHandle"/> values that were determined to be unreachable from the native side.</param> 93ReadOnlySpan<GCHandle> unreachableObjectHandles)
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\ObjectiveC\ObjectiveCMarshal.PlatformNotSupported.cs (2)
90/// The caller is responsible for freeing the returned <see cref="GCHandle"/>. 92public static GCHandle CreateReferenceTrackingHandle(
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\PinnedGCHandle.T.cs (9)
22/// <seealso cref="GCHandle" /> 37_handle = GCHandle.InternalAlloc(target, GCHandleType.Pinned); 52GCHandle.CheckUninitialized(handle); 54return Unsafe.As<T>(GCHandle.InternalGet(handle)!); 59GCHandle.CheckUninitialized(handle); 61GCHandle.InternalSet(handle, value); 105/// interchangable with <see cref="GCHandle"/>. 117/// interchangable with <see cref="GCHandle"/>. 131GCHandle.InternalFree(handle);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\TrackerObjectManager.cs (1)
74foreach (GCHandle weakNativeObjectWrapperHandle in s_referenceTrackerNativeObjectWrapperCache)
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\InteropServices\WeakGCHandle.T.cs (9)
21/// <seealso cref="GCHandle" /> 36_handle = GCHandle.InternalAlloc(target, trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak); 54GCHandle.CheckUninitialized(handle); 56T? obj = Unsafe.As<T>(GCHandle.InternalGet(handle)); 67GCHandle.CheckUninitialized(handle); 68GCHandle.InternalSet(handle, target); 80/// interchangable with <see cref="GCHandle"/>. 92/// interchangable with <see cref="GCHandle"/>. 106GCHandle.InternalFree(handle);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Runtime\Loader\AssemblyLoadContext.cs (6)
102var thisHandle = GCHandle.Alloc(this, IsCollectible ? GCHandleType.WeakTrackResurrection : GCHandleType.Normal); 103var thisHandlePtr = GCHandle.ToIntPtr(thisHandle); 148var thisStrongHandle = GCHandle.Alloc(this, GCHandleType.Normal); 149var thisStrongHandlePtr = GCHandle.ToIntPtr(thisStrongHandle);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\Overlapped.cs (6)
151(nuint)(sizeof(NativeOverlapped) + sizeof(nuint)) + handleCount * (nuint)sizeof(GCHandle)); 161GCHandleRef(pNativeOverlapped, 0) = GCHandle.Alloc(this); 171GCHandleRef(pNativeOverlapped, (nuint)(i + 1)) = GCHandle.Alloc(objArray[i], GCHandleType.Pinned); 177GCHandleRef(pNativeOverlapped, 1) = GCHandle.Alloc(userData, GCHandleType.Pinned); 222private static ref GCHandle GCHandleRef(NativeOverlapped* pNativeOverlapped, nuint index) 223=> ref *((GCHandle*)((nuint*)(pNativeOverlapped + 1) + 1) + index);
src\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\WaitSubsystem.HandleManager.Unix.cs (4)
49IntPtr handle = GCHandle.ToIntPtr(GCHandle.Alloc(waitableObject, GCHandleType.Normal)); 66return (IWaitableObject)GCHandle.FromIntPtr(handle).Target!; 82GCHandle.FromIntPtr(handle).Free();
src\runtime\src\libraries\System.Private.CoreLib\src\System\Threading\WaitSubsystem.Unix.cs (1)
105/// - <see cref="HandleManager"/> currently uses <see cref="Runtime.InteropServices.GCHandle"/> in the interest of
src\runtime\src\libraries\System.Private.CoreLib\src\System\WeakReference.cs (5)
83nint h = GCHandle.InternalAlloc(target, trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak); 132bool result = GCHandle.InternalGet(wh) != null; 184target = GCHandle.InternalGet(th); 216GCHandle.InternalSet(th, value); 238GCHandle.InternalFree(handle);
src\runtime\src\libraries\System.Private.CoreLib\src\System\WeakReference.T.cs (3)
83nint h = GCHandle.InternalAlloc(target, trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak); 120GCHandle.InternalSet(th, target); 159target = Unsafe.As<T>(GCHandle.InternalGet(th));
System\Runtime\InteropServices\TrackerObjectManager.NativeAot.cs (4)
157foreach (GCHandle weakNativeObjectWrapperHandle in s_referenceTrackerNativeObjectWrapperCache) 184foreach (GCHandle weakNativeObjectWrapperHandle in s_referenceTrackerNativeObjectWrapperCache) 208public GCHandle RootObject; 210public Instance(GCHandle handle)
System.Private.Reflection.Execution (2)
Internal\Reflection\Execution\ExecutionEnvironmentImplementation.MappingTables.cs (1)
269GCHandle reader = Internal.TypeSystem.LockFreeObjectInterner.GetInternedObjectHandle(methodHandle.Reader);
Internal\Reflection\Execution\MethodInvokers\InstanceMethodInvoker.cs (1)
137new OpenMethodResolver(_declaringTypeHandle, MethodInvokeInfo.LdFtnResult, default(GCHandle), 0, resolveType).ToIntPtr(),
System.Private.TypeLoader (12)
Internal\Runtime\TypeLoader\LockFreeObjectInterner.cs (12)
9public class LockFreeObjectInterner : LockFreeReaderHashtableOfPointers<object, GCHandle> 12public static GCHandle GetInternedObjectHandle(object obj) 29protected override int GetValueHashCode(GCHandle value) 38protected override bool CompareKeyToValue(object key, GCHandle value) 47protected override bool CompareValueToValue(GCHandle value1, GCHandle value2) 56protected override GCHandle CreateValueFromKey(object key) 58return GCHandle.Alloc(key); 64protected override IntPtr ConvertValueToIntPtr(GCHandle value) 66return GCHandle.ToIntPtr(value); 72protected override GCHandle ConvertIntPtrToValue(IntPtr pointer) 74return GCHandle.FromIntPtr(pointer);
System.Private.Windows.Core (19)
Windows\Win32\PInvokeCore.EnumChildWindows.cs (3)
23GCHandle gcHandle = GCHandle.Alloc(callback); 44return ((EnumChildWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\PInvokeCore.EnumDisplayMonitors.cs (3)
19GCHandle gcHandle = GCHandle.Alloc(callBack); 39return ((EnumDisplayMonitorsCallback)((GCHandle)(nint)lParam).Target!)(monitor, hdc);
Windows\Win32\PInvokeCore.EnumThreadWindows.cs (3)
25GCHandle gcHandle = GCHandle.Alloc(callback); 48return ((EnumThreadWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\PInvokeCore.EnumWindows.cs (3)
22GCHandle gcHandle = GCHandle.Alloc(callback); 42return ((EnumWindowsCallback)((GCHandle)(nint)lParam).Target!)(hWnd);
Windows\Win32\System\Com\Lifetime.cs (5)
31GCHandle.FromIntPtr((nint)lifetime->_handle).Free(); 44/// This creates a <see cref="GCHandle"/> to root the <paramref name="object"/> until ref 58wrapper->_handle = (void*)GCHandle.ToIntPtr(GCHandle.Alloc(@object)); 75return (TObject?)GCHandle.FromIntPtr((IntPtr)lifetime->_handle).Target;
Windows\Win32\System\Variant\VARIANT.cs (2)
272GCHandle pin = default; 276pin = GCHandle.Alloc(array, GCHandleType.Pinned);
System.Reflection.Metadata (5)
System\Reflection\Internal\Utilities\PinnedObject.cs (2)
13private GCHandle _handle; 28_handle = GCHandle.Alloc(obj, GCHandleType.Pinned);
System\Reflection\Metadata\Internal\VirtualHeap.cs (3)
24public GCHandle Handle; 28public PinnedBlob(GCHandle handle, int length) 103var blob = new PinnedBlob(GCHandle.Alloc(value, GCHandleType.Pinned), value.Length);
System.Resources.Extensions (2)
src\runtime\src\libraries\System.Private.CoreLib\src\System\IO\PinnedBufferMemoryStream.cs (2)
15private GCHandle _pinningHandle; 22_pinningHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
System.Runtime (1)
src\runtime\artifacts\obj\System.Runtime\Release\net11.0\System.Runtime.Forwards.cs (1)
680[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.GCHandle))]
System.Runtime.Caching (2)
System\Runtime\Caching\SRef.cs (2)
31private GCHandle _handle; 36_handle = GCHandle.Alloc(t);
System.Runtime.InteropServices (1)
src\runtime\artifacts\obj\System.Runtime.InteropServices\Release\net11.0\System.Runtime.InteropServices.Forwards.cs (1)
91[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.InteropServices.GCHandle))]
System.Runtime.InteropServices.JavaScript (22)
System\Runtime\InteropServices\JavaScript\Interop\JavaScriptExports.CoreCLR.cs (4)
50GCHandle callback_gc_handle = (GCHandle)arg1.slot.GCHandle; 109GCHandle exception_gc_handle = (GCHandle)arg1.slot.GCHandle;
System\Runtime\InteropServices\JavaScript\JSFunctionBinding.cs (2)
357var holderHandle = (GCHandle)arguments[1].slot.GCHandle;
System\Runtime\InteropServices\JavaScript\JSHostImplementation.Types.cs (1)
26GCHandle = (IntPtr)InteropServices.GCHandle.Alloc(this, GCHandleType.Normal);
System\Runtime\InteropServices\JavaScript\JSProxyContext.cs (9)
331IntPtr result = (IntPtr)GCHandle.Alloc(obj, handleType); 364holder = (PromiseHolder)((GCHandle)gcHandle).Target!; 387GCHandle handle = (GCHandle)holderGCHandle; 427GCHandle handle = (GCHandle)gcHandle; 561GCHandle gcHandle = (GCHandle)gch; 570((GCHandle)holder.GCHandle).Free();
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Byte.cs (1)
125var array = (byte[])((GCHandle)slot.GCHandle).Target!;
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Double.cs (1)
131var array = (double[])((GCHandle)slot.GCHandle).Target!;
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Exception.cs (1)
29value = (Exception)((GCHandle)slot.GCHandle).Target;
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Int32.cs (1)
125var array = (int[])((GCHandle)slot.GCHandle).Target!;
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Object.cs (1)
32value = ((GCHandle)slot.GCHandle).Target;
System\Runtime\InteropServices\JavaScript\Marshaling\JSMarshalerArgument.Single.cs (1)
131var array = (float[])((GCHandle)slot.GCHandle).Target!;
System.Security.Cryptography (2)
System\Security\Cryptography\CryptoStream.cs (2)
724GCHandle pinHandle = GCHandle.Alloc(rentedBuffer, GCHandleType.Pinned);
System.Security.Principal.Windows (3)
System\Security\Principal\SID.cs (3)
951GCHandle[] HandleArray = new GCHandle[sourceSids.Count]; 970HandleArray[currentSid] = GCHandle.Alloc(sid.BinaryForm, GCHandleType.Pinned);
System.ServiceProcess.ServiceController (2)
System\ServiceProcess\ServiceController.cs (2)
893GCHandle argPtrsHandle = default; 896argPtrsHandle = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
System.Speech (60)
Internal\SapiInterop\SapiRecoInterop.cs (9)
432internal static ISpPhrase CreatePhraseFromText(string phrase, CultureInfo culture, out GCHandle[] memHandles, out IntPtr coMem) 448internal static ISpPhrase CreatePhraseFromWordUnits(RecognizedWordUnit[] words, CultureInfo culture, out GCHandle[] memHandles, out IntPtr coMem) 454List<GCHandle> handles = new(); 476GCHandle handle = GCHandle.Alloc(word.Text, GCHandleType.Pinned); 483GCHandle handle = GCHandle.Alloc(word.LexicalForm, GCHandleType.Pinned); 494GCHandle handle = GCHandle.Alloc(word.Pronunciation, GCHandleType.Pinned);
Internal\Synthesis\AudioBase.cs (8)
55GCHandle gc = GCHandle.Alloc(buffer); 380GCHandle gc = GCHandle.Alloc(waveHeader, GCHandleType.Pinned); 403GCHandle gc = GCHandle.Alloc(waveHeader, GCHandleType.Pinned); 413GCHandle gc = GCHandle.Alloc(this, GCHandleType.Pinned);
Internal\Synthesis\AudioDeviceOut.cs (1)
146GCHandle waveHdr = waveHeader.WAVEHDR;
Internal\Synthesis\ConvertTextFrag.cs (6)
14internal static bool ToSapi(List<TextFragment> ssmlFrags, ref GCHandle sapiFragLast) 33sapiFrag.gcText = GCHandle.Alloc(textFragment.TextToSpeak, GCHandleType.Pinned); 67sapiFrag.gcPhoneme = GCHandle.Alloc(ssmlState.Phoneme, GCHandleType.Pinned); 109sapiFragLast = GCHandle.Alloc(sapiFrag, GCHandleType.Pinned); 120sapiFrag.gcSayAsCategory = GCHandle.Alloc(sFormat, GCHandleType.Pinned); 124internal static void FreeTextSegment(ref GCHandle fragment)
Internal\Synthesis\TTSEngineProxy.cs (5)
61GCHandle gc = GCHandle.Alloc(wfx, GCHandleType.Pinned); 148GCHandle gc = GCHandle.Alloc(wfx, GCHandleType.Pinned); 152GCHandle spvTextFragment = new();
Internal\Synthesis\TTSVoice.cs (2)
94GCHandle targetFormat = new(); 98targetFormat = GCHandle.Alloc(targetWaveFormat, GCHandleType.Pinned);
Internal\Synthesis\WaveHeader.cs (5)
20_gcHandle = GCHandle.Alloc(buffer, GCHandleType.Pinned); 66internal GCHandle WAVEHDR 79_gcHandleWaveHdr = GCHandle.Alloc(_waveHdr, GCHandleType.Pinned); 141private GCHandle _gcHandle; 143private GCHandle _gcHandleWaveHdr;
Recognition\RecognizerBase.cs (4)
1578GCHandle gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned); 1894GCHandle[]? memHandles = null; 1916foreach (GCHandle memHandle in memHandles)
Result\RecognitionResult.cs (8)
156GCHandle gc = GCHandle.Alloc(_sapiAudioBlob, GCHandleType.Pinned); 296GCHandle gc = GCHandle.Alloc(sapiResultBlob, GCHandleType.Pinned); 357GCHandle gc = GCHandle.Alloc(_sapiAlternatesBlob, GCHandleType.Pinned); 484GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned);
Result\RecognizedPhrase.cs (8)
166GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned); 290GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned); 412GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned); 782GCHandle gc = GCHandle.Alloc(_phraseBuffer, GCHandleType.Pinned);
Synthesis\TTSEngine\SAPIEngineTypes.cs (4)
30public GCHandle gcText; 31public GCHandle gcNext; 32public GCHandle gcPhoneme; 33public GCHandle gcSayAsCategory;
System.Windows.Forms (22)
System\Windows\Forms\Control.ControlNativeWindow.cs (2)
13private GCHandle _rootRef; // We will root the control when we do not want to be eligible for garbage collection. 43_rootRef = GCHandle.Alloc(GetControl(), GCHandleType.Normal);
System\Windows\Forms\Dialogs\CommonDialogs\FolderBrowserDialog.cs (4)
453GCHandle handle = GCHandle.Alloc(this); 463GCHandle.ToIntPtr(handle)); 494var instance = (FolderBrowserDialog)GCHandle.FromIntPtr(lpData).Target!;
System\Windows\Forms\Dialogs\TaskDialog\TaskDialog.cs (4)
81/// The <see cref="IntPtr"/> of a <see cref="GCHandle"/> that represents this 276(((GCHandle)lpRefData).Target as TaskDialog)!.HandleTaskDialogCallback( 559var instanceHandle = GCHandle.Alloc(this);
System\Windows\Forms\NativeWindow.cs (8)
38private static readonly Dictionary<HWND, GCHandle> s_windowHandles = []; 245GCHandle root = GCHandle.Alloc(window, GCHandleType.Weak); 247if (s_windowHandles.TryGetValue(handle, out GCHandle oldRoot)) 561s_windowHandles.TryGetValue(handle, out GCHandle value) && value.IsAllocated 613foreach ((HWND handle, GCHandle gcHandle) in s_windowHandles) 708if (!s_windowHandles.TryGetValue(hwnd, out GCHandle root)) 735s_windowHandles[hwnd] = GCHandle.Alloc(window.PreviousWindow, GCHandleType.Weak);
System\Windows\Forms\NotifyIcon.NotifyIconNativeWindow.cs (2)
16private GCHandle _rootRef; // We will root the control when we do not want to be eligible for garbage collection. 43_rootRef = GCHandle.Alloc(_reference, GCHandleType.Normal);
System\Windows\Forms\Timer.cs (2)
25private GCHandle _timerRoot; 114_timerRoot = GCHandle.Alloc(this);
System.Windows.Forms.Primitives (4)
Windows\Win32\PInvoke.SendMessageCallback.cs (4)
19GCHandle gcHandle = GCHandle.Alloc(callback); 28GCHandle gcHandle = (GCHandle)(nint)dwData;
UIAutomationClient (8)
MS\Internal\Automation\EventListenerClientSide.cs (2)
32_gch = GCHandle.Alloc(_callbackDelegate); 294private GCHandle _gch; // GCHandle to keep GCs from moving the callback
MS\Internal\Automation\HwndProxyElementProvider.cs (2)
1576GCHandle gch = GCHandle.Alloc(enumWindows);
MS\Internal\Automation\UiaCoreApi.cs (2)
1555private static GCHandle _gchandle; 1560_gchandle = GCHandle.Alloc(onGetProviderDelegate);
MS\Internal\Automation\WinEventWrap.cs (2)
240_gchThis = GCHandle.Alloc(_winEventProc); 280private GCHandle _gchThis; // GCHandle to keep GCs from moving this callback
UIAutomationClientSideProviders (6)
MS\Internal\AutomationProxies\Misc.cs (2)
349GCHandle gch = GCHandle.Alloc(enumToolTipWindows);
MS\Internal\AutomationProxies\MSAAWinEventWrap.cs (2)
171_gchThis = GCHandle.Alloc(_winEventProc); 221private GCHandle _gchThis; // GCHandle to keep GCs from moving this callback
MS\Internal\AutomationProxies\WinEventTracker.cs (2)
124internal GCHandle _procHookHandle; 173hp._procHookHandle = GCHandle.Alloc (proc);