src/Microsoft.IdentityModel.Tokens/ObjectPools.cs
/// <summary>
/// Returns objects to the pool.
/// </summary>
/// <remarks>
/// Search strategy is a simple linear probing which is chosen for it cache-friendliness.
/// Note that Free will try to store recycled objects close to the start thus statistically
/// reducing how far we will typically search in Allocate.
/// </remarks>
Returns objects to the pool.
Returns objects to the pool .
internal void Free(T obj)
        {
            var items = Items;
            bool returned = false;
            for (int i = 0; i < items.Length; i++)
            {
                if (items[i].Value == null)
                {
                    if (null == Interlocked.CompareExchange(ref items[i].Value, obj, null))
                    {
                        returned = true;
                        break;
                    }
                }
            }
            if (!returned)
            {
                obj.Dispose();
            }
        }
internal void Free ( T obj ) { var items = Items ; bool returned = false ; for ( int i = 0 ; i < items . Length ; i ++ ) { if ( items [ i ] . Value == null ) { if ( null == Interlocked . CompareExchange ( ref items [ i ] . Value , obj , null ) ) { returned = true ; break ; } } } if ( ! returned ) { obj . Dispose ( ) ; } }
Returns objects to the pool.
Returns objects to the pool .
// We need to know if we returned the object. If we didn't, it needs to get disposed. // Our pool is full, we can't hold on to this object, so it will get dropped / garbage collected. // However this object was disposable, so we should dispose it now, else the disposal work // would have to be done by the finalizer, which may impact high performance scenarios (since the finalizer queue is worked on sequentially.)
obj
T
remarks
Search strategy is a simple linear probing which is chosen for it cache-friendliness.
Note that Free will try to store recycled objects close to the start thus statistically
reducing how far we will typically search in Allocate.
Search strategy is a simple linear probing which is chosen for it cache - friendliness . Note that Free will try to store recycled objects close to the start thus statistically reducing how far we will typically search in Allocate .