Hi guys,
I have an issue with destruction of objects created with NewObject(pointer, name) function. I had a memory leak in my project and I was tracking it down for more than a week and I found it was caused by this.
From wikihere I am using the MyObject->ConditionalBeginDestroy(); //instantly clears UObject out of memory
, but it does not work.
Steps to replicate:
Here is my test code: Newly generated TestActor class and TestObject class.
// Called every frame
void ATestActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
for (int i = 0; i < 300; i++)
{
FName RendererName = FName(*("TestObjectInst" + FString::FromInt(FMath::RandRange(0, 999999999))));
UTestObject* testObject = NewObject<UTestObject>(this, RendererName);
if (testObject->IsValidLowLevel()) {
testObject->ConditionalBeginDestroy(); //instantly clears UObject out of memory
testObject = nullptr;
UE_LOG(LogTemp, Warning, TEXT("MarkingToDestroy"));
}
}
}
After running this for couple seconds, I end up with gigs more ram allocated to UE4. Even stopping playing the game does not release the memory.
What did I miss or is it a bug?
Cheers,
Crispy