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); }
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-272934 in the post.
1 |
Component | UE - Framework - Blueprint |
---|---|
Affects Versions | 5.5 |
Target Fix | 5.6 |
Fix Commit | 42122229 |
---|
Created | Apr 15, 2025 |
---|---|
Resolved | Apr 30, 2025 |
Updated | May 8, 2025 |