Will raw pointer, new keyword, in UFunction body, cause memory leak?

anonymous_user_91b492f1
Sun, 15 Sep 2019 22:11:23 +0000
Rendering

I followed this tutorial: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums to create a static library.

It is a great tutorial. However I noticed when implementing a UFunction, they create a c++ object using the new keyword, allocating memory, than return from the function without deleting the memory.

so my question is, since this is happening inside of a UFunction, is the memory managed? Or is this a memory leak?

.h
UCLASS()
class UE4MAGIC_API UYJLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

		UFUNCTION(BlueprintCallable, meta = (DisplayName = "Adds floats", Keywords = "Float Add"), Category = YJLibrary)
		static float AddFloats(float A, float B);

};

.cpp
#include "YJLibrary.h"
#include "YJMagic.h"

float UYJLibrary::AddFloats(float A, float B)
{
	YJMagic::YJMagic *PointerToYJMagic;

	PointerToYJMagic = new YJMagic::YJMagic();

	return PointerToYJMagic->Add(A, B);
}

1 post - 1 participant