Ejemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            // disposing == false when finilizing and detected that non pooled
            if (disposing)
            {
                var pool = Pool;
                if (pool != null)
                {
                    pool.ReturnInternal(this, clearMemory: false);
                    // pool calls Dispose(false) is a bucket is full
                    return;
                }

                // not pooled, doing finalization work now
                GC.SuppressFinalize(this);
            }

            Debug.Assert(!_isPooled);
            _poolIdx = default;

            AtomicCounter.Dispose(ref CounterRef);
            _isNativeWithHeader = false;
            CounterRef          = AtomicCounter.CountMask;

            ClearAfterDispose();

            // Dispose destructs this object and native buffer
            _offHeapBuffer.Dispose();
            // set all to default, increase chances to detect errors
            _offHeapBuffer = default;
        }
Ejemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            EnsureNotRetainedAndNotDisposed();

            // disposing == false when finilizing and detected that non pooled
            if (disposing)
            {
                TryReturnThisToPoolOrFinalize();
            }
            else
            {
                Debug.Assert(!_isPooled);
                _pool = null;

                Counter.Dispose();
                AtomicCounterService.ReleaseCounter(Counter);
                ClearAfterDispose();

                // Dispose destructs this object and native buffer
                _offHeapBuffer.Dispose();
                // set all to default, increase chances to detect errors
                _offHeapBuffer = default;
            }
        }