Description

When Calling UBlueprintMapLibrary::GenericMap_Find with a non-existent key, the function construct the default structure in-place on the given pointer without destroying the object.
This behavior causes a memory leak.

The following fix works :

bool UBlueprintMapLibrary::GenericMap_Find(const void* TargetMap, const FMapProperty* MapProperty, const void* KeyPtr, void* OutValuePtr)
{
	if(TargetMap)
	{
		FScriptMapHelper MapHelper(MapProperty, TargetMap);
		uint8* FoundValuePtr = MapHelper.FindValueFromHash(KeyPtr);
		if (OutValuePtr)
		{
			if (FoundValuePtr)
			{
				MapProperty->ValueProp->CopyCompleteValueFromScriptVM(OutValuePtr, FoundValuePtr);
			}
			else
			{
#if 1 //fix for it
				MapProperty->ValueProp->ClearValue(OutValuePtr);
#else
				MapProperty->ValueProp->InitializeValue(OutValuePtr);
#endif
			}
		}
		return FoundValuePtr != nullptr;
	}
	return false;
}

 
These locals are initialized by the interpreter itself:

template<typename Exec>
void ProcessScriptFunction(UObject* Context, UFunction* Function, FFrame& Stack, RESULT_DECL, Exec ExecFtor)
{
...
	if (!bUsePersistentFrame)
	{
		// Initialize any local properties that aren't CPF_ZeroConstruct:
		for (FProperty* LocalProp = Function->FirstPropertyToInit; LocalProp != nullptr; LocalProp = (FProperty*)(LocalProp->PostConstructLinkNext))
		{
			LocalProp->InitializeValue_InContainer(NewStack.Locals);
		}
	}

This results in double init - which leaks memory for types that allocate in their ctor ala the attached project:

FSampleContainerStruct::FSampleContainerStruct()
{
	LLM_SCOPE(ELLMTag::EngineMisc);

	IntArray.SetNum(1024);
	FloatArray.SetNum(1024);
	VectorArray.SetNum(1024);
}

 

Steps to Reproduce
  1. Build and launch attached repro project
  2. Start standalone game with -LLM command line option
  3. Once launched the game, enter stat LLMFULL in console
  4. See EngineMisc tag in stat display

Result:

EngineMisc counter in stat display keeps increasing

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-272934 in the post.

1
Login to Vote

Fixed
ComponentUE - Framework - Blueprint
Affects Versions5.5
Target Fix5.6
Fix Commit42122229
CreatedApr 15, 2025
ResolvedApr 30, 2025
UpdatedMay 8, 2025
View Jira Issue