本文整理汇总了C#中ObjectPool.Release方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectPool.Release方法的具体用法?C# ObjectPool.Release怎么用?C# ObjectPool.Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectPool
的用法示例。
在下文中一共展示了ObjectPool.Release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPoolRelease
public void TestPoolRelease()
{
var pool = new ObjectPool<TestElement>();
pool.Initialize(() => { var e = new TestElement(); e.value = 42; return e; });
// allocate a new instance using this custom factory, make sure the factory code got called
var e1 = pool.Allocate();
Assert.IsTrue(e1.value == 42);
Assert.IsTrue(pool.UsedListSize == 1);
Assert.IsTrue(pool.FreeListSize == 0);
// allocate and free an instance. this will grow the pool to size one
pool.Free(pool.Allocate());
Assert.IsTrue(pool.UsedListSize == 1);
Assert.IsTrue(pool.FreeListSize == 1);
// now release the entire object pool. this will clear out the free list, but will not
// affect the object already in circulation, since we're not tracking them.
pool.Release();
Assert.IsTrue(e1.value == 42);
Assert.IsTrue(pool.UsedListSize == 1);
Assert.IsTrue(pool.FreeListSize == -1);
}