Memory Leak on animation blueprint

Hello,

We have currently a memory leak with our animation blueprints.

The memory allocation keep increasing .

We are currently using metahuman’s animation blueprint structure. With “mesh”, “body”, “head” animation blueprint using "Copy pose from mesh". Some animeblueprints are using "cache pose ".

In the PostGraphUpdate of animNode_SaveCachedPose.cpp, Unreal destroys a TSharedPtr pointing to an FAnimationUpdateSharedContext, but since at that moment there are 2 SharedRefs and 1 WeakRef on this FAnimationUpdateSharedContext, this might be where the leak occurs.

Thanks for your help!

Steps to Reproduce

Hi, sorry for the delay in following up on this. I’ve spent a bit of time trying to get a repro which slowed things down.

Do you know where the other shared reference is coming from? Do you have any custom code that references SharedContext, or is there a particular setup you have with the Save Cached Pose nodes in your animation graph?

When I was testing this, I was only ever able to see 1 shared reference (from FAnimNode_SaveCachedPose::CachedUpdateContexts) and 1 weak reference. That was the case even when I had multiple branches within the graph that referenced the same cached pose.

The fix for this is probably going to be to change SharedContext to a TUniquePtr since ownership of it should be tied to CachedUpdateContexts. When CachedUpdateContexts is reset in FAnimNode_SaveCachedPose::PostGraphUpdate we should destroy SharedContext.

Quick follow-up on this. I have a shelf that converts SharedContext into a TUniquePtr, along with some associated changes, at 47918947. Are you able to try integrating that? It’d be useful to know if that resolves the leak for you.