# Metal PSO 预热内存问题 

**URL:** <https://forums.unrealengine.com/t/metal-pso/2695451>\
**Category:** Platform & Builds\
**Tags:** unreal-engine, Epic-Pro-Support, question\
**Created:** [December 26, 2025, 12:29pm UTC](https://forums.unrealengine.com/t/metal-pso/2695451 "2025-12-26T12:29:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [December 26, 2025, 12:29pm UTC](https://forums.unrealengine.com/t/metal-pso/2695451/1 "2025-12-26T12:29:19Z")

</div>

[Image Removed]

hi，ios预热pso后，内存增长近百M，像是PSO内存没有卸载，项目里面 rhi.Metal.CacheShaderPipelines 配置的是0

发现 FMetalCompiledShaderCache 有个成员 TMap\<FMetalCompiledShaderKey, mtlpp::Function\> Cache，会缓存底层的 mtlpp::Function，这里是否要在 TMetalBaseShader 销毁的地方手动释放一下，比如下面这样

```auto
template<typename BaseResourceType, int32 ShaderType>
void TMetalBaseShader<BaseResourceType, ShaderType>::Destroy()
{
	@autoreleasepool{
			[GlslCodeNSString release];

			//Add Begin
			Function = nil;
			Library = nil;

			uint32 FunctionConstantHash = ConstantValueHash;
			FMetalCompiledShaderKey Key(SourceLen, SourceCRC, FunctionConstantHash);
			GetMetalCompiledShaderCache().Remove(Key);
			//Add End
	}
}

struct FMetalCompiledShaderCache
{
bool Remove(FMetalCompiledShaderKey Key)
{
	bool bReleased = false;

	@autoreleasepool{
		FRWScopeLock ScopedLock(Lock, SLT_Write);
		if (Cache.FindRef(Key) != nil)
		{
			mtlpp::Function::Type FuncPtr = Cache.FindRef(Key).GetPtr();

			LibCache.Remove(FuncPtr);

			Cache.Remove(Key);

			bReleased = true;
		}
	}
	return bReleased;
}
}

```

[Attachment Removed]

---

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [December 26, 2025, 12:29pm UTC](https://forums.unrealengine.com/t/metal-pso/2695451/2 "2025-12-26T12:29:23Z")

</div>

**Steps to Reproduce**  
ios pso预热即可复现

[Attachment Removed]

---

<div class="post-metadata">

**Author:** ![Liu.Wei](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Liu.Wei](https://forums.unrealengine.com/u/Liu.Wei)\
**Post date:** [December 30, 2025, 3:31am UTC](https://forums.unrealengine.com/t/metal-pso/2695451/3 "2025-12-30T03:31:56Z")

</div>

Hi,

你好，4.27的版本确实有这个问题，mtlpp以及引擎层都有一些引用和cache导致function以及没有用到的pso没有被释放。我映像里mtlpp里也需要做一些修改，否则可能也释放不了function，之前好像看过一些，但是好像没有完成，只能给你一些线索。

另外这里有篇文章介绍了一些Vulkan上的思路，供参考 [https://zhuanlan.zhihu.com/p/669562389。](https://zhuanlan.zhihu.com/p/669562389%E3%80%82)

[Image Removed]

[Attachment Removed]
