public void Dispose()
            {
                if (Parent == null)
                {
                    return; // disposed already
                }
                if (Context.DoNotReuse)
                {
                    Context.Dispose();
                    return;
                }

                if (Context.AllocatedMemory > Parent._maxContextSizeToKeepInBytes)
                {
                    Context.Dispose();
                    return;
                }

                if (Parent.LowMemoryFlag.IsRaised() && Context.PoolGeneration < Parent._generation)
                {
                    // releasing all the contexts which were created before we got the low memory event
                    Context.Dispose();
                    return;
                }

                Context.Reset();
                // These contexts are reused, so we don't want to use LowerOrDie here.
                Context.InUse.Lower();
                Context.InPoolSince = DateTime.UtcNow;

                Parent.Push(Context);

                Parent  = null;
                Context = null;
            }
Beispiel #2
0
            public void Dispose()
            {
                if (Parent == null)
                {
                    return;// disposed already
                }
                if (Context.DoNotReuse)
                {
                    Context.Dispose();
                    return;
                }

                Context.Reset();
                // These contexts are reused, so we don't want to use LowerOrDie here.
                Context.InUse.Lower();
                Context.InPoolSince = DateTime.UtcNow;

                Parent.Push(Context);

                Parent  = null;
                Context = null;
            }
Beispiel #3
0
 public void RemoveContextPool(JsonContextPoolBase <T> parent)
 {
     _parents.Remove(parent);
 }
Beispiel #4
0
 public bool AddContextPool(JsonContextPoolBase <T> parent)
 {
     return(_parents.Add(parent));
 }