protected internal virtual unsafe void Reset(bool forceReleaseLongLivedAllocator = false)
        {
            _documentBuilder.Reset();

            // We don't reset _arenaAllocatorForLongLivedValues. It's used as a cache buffer for long lived strings like field names.
            // When a context is re-used, the buffer containing those field names was not reset and the strings are still valid and alive.

            var allocatorForLongLivedValues = _arenaAllocatorForLongLivedValues;

            if (allocatorForLongLivedValues != null || forceReleaseLongLivedAllocator)
            {
                _arenaAllocatorForLongLivedValues = null;
            }
            _numberOfAllocatedStringsValues = 0;

            if (_pooledArrays != null)
            {
                foreach (var pooledTypesKVP in _pooledArrays)
                {
                    foreach (var pooledArraysOfCurrentType in pooledTypesKVP.Value.Array)
                    {
                        pooledTypesKVP.Value.Releaser(pooledArraysOfCurrentType);
                    }
                }

                _pooledArrays = null;
            }
        }
Exemple #2
0
        protected internal virtual unsafe void Reset(bool forceReleaseLongLivedAllocator = false)
        {
            if (_tempBuffer != null && _tempBuffer.Address != null)
            {
                _arenaAllocator.Return(_tempBuffer);
                _tempBuffer = null;
            }

            _documentBuilder.Reset();

            // We don't reset _arenaAllocatorForLongLivedValues. It's used as a cache buffer for long lived strings like field names.
            // When a context is re-used, the buffer containing those field names was not reset and the strings are still valid and alive.

            var allocatorForLongLivedValues = _arenaAllocatorForLongLivedValues;

            if (allocatorForLongLivedValues != null &&
                (allocatorForLongLivedValues.Allocated > _initialSize || forceReleaseLongLivedAllocator))
            {
                foreach (var mem in _fieldNames.Values)
                {
                    _arenaAllocatorForLongLivedValues.Return(mem.AllocatedMemoryData);
                    mem.AllocatedMemoryData = null;
                    mem.Dispose();
                }

                _arenaAllocatorForLongLivedValues = null;

                // at this point, the long lived section is far too large, this is something that can happen
                // if we have dynamic properties. A back of the envelope calculation gives us roughly 32K
                // property names before this kicks in, which is a true abuse of the system. In this case,
                // in order to avoid unlimited growth, we'll reset the long lived section
                allocatorForLongLivedValues.Dispose();

                _fieldNames.Clear();
                CachedProperties = null; // need to release this so can be collected
            }
            _objectJsonParser.Reset(null);
            _arenaAllocator.ResetArena();
            _numberOfAllocatedStringsValues = 0;
            _generation = _generation + 1;
        }
Exemple #3
0
        protected internal virtual unsafe void Reset()
        {
            if (_tempBuffer != null)
            {
                _arenaAllocator.Return(_tempBuffer);
                _tempBuffer.Address = null;
            }

            foreach (var builder in _liveReaders)
            {
                builder.DisposeTrackingReference = null;
                builder.Dispose();
            }

            _liveReaders.Clear();
            _arenaAllocator.ResetArena();

            _documentBuilder.Reset();

            if (_tempBuffer != null)
            {
                GetNativeTempBuffer(_tempBuffer.SizeInBytes);
            }

            // We don't reset _arenaAllocatorForLongLivedValues. It's used as a cache buffer for long lived strings like field names.
            // When a context is re-used, the buffer containing those field names was not reset and the strings are still valid and alive.

            if (_arenaAllocatorForLongLivedValues.Allocated > _initialSize)
            {
                // at this point, the long lived section is far too large, this is something that can happen
                // if we have dynamic properties. A back of the envelope calculation gives us roughly 32K
                // property names before this kicks in, which is a true abuse of the system. In this case,
                // in order to avoid unlimited growth, we'll reset the long lived section
                _arenaAllocatorForLongLivedValues.Dispose();
                _arenaAllocatorForLongLivedValues = null;
                _fieldNames.Clear();
                CachedProperties = null; // need to release this so can be collected
            }
        }