System.Threading.AutoreleasePool.DrainAutoreleasePool C# (CSharp) Method

DrainAutoreleasePool() static private method

static private DrainAutoreleasePool ( ) : void
return void
        internal static void DrainAutoreleasePool()
        {
            if (EnableAutoreleasePool
                && s_AutoreleasePoolInstance != IntPtr.Zero)
            {
                Interop.Sys.DrainAutoreleasePool(s_AutoreleasePoolInstance);
                s_AutoreleasePoolInstance = IntPtr.Zero;
            }
        }
    }

Usage Example

Esempio n. 1
0
            [MethodImpl(MethodImplOptions.AggressiveInlining)] // avoid long-lived stack frame in many threads
            private void RunWorker()
            {
                InitializeCulture();

                Delegate start = _start;

                _start = null !;

#if FEATURE_OBJCMARSHAL
                if (AutoreleasePool.EnableAutoreleasePool)
                {
                    AutoreleasePool.CreateAutoreleasePool();
                }
#endif

                if (start is ThreadStart threadStart)
                {
                    threadStart();
                }
                else
                {
                    ParameterizedThreadStart parameterizedThreadStart = (ParameterizedThreadStart)start;

                    object?startArg = _startArg;
                    _startArg = null;

                    parameterizedThreadStart(startArg);
                }

#if FEATURE_OBJCMARSHAL
                // There is no need to wrap this "clean up" code in a finally block since
                // if an exception is thrown above, the process is going to terminate.
                // Optimize for the most common case - no exceptions escape a thread.
                if (AutoreleasePool.EnableAutoreleasePool)
                {
                    AutoreleasePool.DrainAutoreleasePool();
                }
#endif
            }