NumericFactory/Books/3-3-内存池模块.md
2025-04-21 21:14:23 +08:00

23 lines
614 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 3-3.内存池模块 - MemoryPool
内存池更为轻量化,相对于对象池更适合一些更抽象碎片化的内存对象。
Scene窗口MemoryPool对象可以设置内存池检查防止回收问题与内存泄漏问题。
![image](src/3-3-1.png)
使用案例
``` csharp
/// <summary>
/// 资源组数据。
/// <remarks>DisposeGroup。</remarks>
/// </summary>
public class AssetGroup : IMemory
{
public void Clear(){}
}
//内存池中获取/生成内存对象。
AssetGroup assetGroup = MemoryPool.Acquire<AssetGroup>();
//释放内存对象还给内存池。
MemoryPool.Release(assetGroup);
```